ubuntu 安装配备jdk+eclipse+android sdk

共5步:

微软EnterLib的Policy Injection Application
Block(PIAB)是贰个相比好用的轻量级的AOP框架,你能够由此创办自定义的CallHandler完成有些克罗丝Cutting的逻辑,并以自定义性情或然安顿的章程利用到对象措施方面。PIAB本身也提供了一多重的CallHandler,个中CachingCallHandler直接使用HttpRuntime的Cache落成了依照方法级其他缓存。不过,PIAB发表到明天,CachingCallHandler就一贯存着四个难点:假若指标措施具有Out参数并且重临类型不是void,会抛出IndexOutOfRangeException,假设回去类型为void,out参数也不会被缓存。不知晓微软对此作何考虑,反正笔者以为那是四个不行原谅的Bug。(Source
Code从这里下载)

1、安装jdk

壹 、难题再次出现

2、安装eclipse

本条题材还还重现,为了比较大家先来探望符合规律情状下CachingCallHandler的呈现。下边小编定义了三个简约的接口:IMembershipService,
包蕴一个艺术GetUserName依据传入的User ID重临User
Name。MembershipService完毕了该接口,为了有利于咱们分明方法执行的结果是或不是被缓存,作者让每便执行都回去四个GUID。CachingCallHandler间接以自定义脾性的章程选择到GetUserName方法上。

3、安装android-sdk

   1: using System;

   2: using System.Threading;

   3: using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;

   4: namespace CachingCallHandler4OutParam

   5: {

   6:     public interface IMembershipService

   7:     {

   8:         string GetUserName(string userId);

   9:     }

  10:  

  11:     public class MembershipService : IMembershipService

  12:     {        

  13:         [CachingCallHandler]

  14:         public string GetUserName(string userId)

  15:         {

  16:             return Guid.NewGuid().ToString();

  17:         }

  18:     }

  19: }

4、安装adb

现今,在Main方法中,编写如下的代码:通过PolicyInjection的Create<TType,
TInterface>创造能够被PIAB截获的Proxy对象,并在三个极其循环中流传相同的参数调用GetUserName方法。从输出结果我们看出,再次回到的UserName都以一样的,从而证实了第一次实践的结果被成功缓存。

5、在eclipse中安装ADT

   1: using System;

   2: using System.Threading;

   3: using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;

   4: namespace CachingCallHandler4OutParam

   5: {

   6:     class Program

   7:     {

   8:         static void Main(string[] args)

   9:         {

  10:             IMembershipService svc = PolicyInjection.Create<MembershipService, IMembershipService>();

  11:             while(true)

  12:             {                

  13:                 Console.WriteLine(svc.GetUserName("007"));

  14:                 Thread.Sleep(1000);

  15:             }

  16:         }

  17:     }    

  18: }

 

输出结果:

1、安装jdk

E1E8EA0F-7620-4879-BA5D-33356568336E

E1E8EA0F-7620-4879-BA5D-33356568336E

E1E8EA0F-7620-4879-BA5D-33356568336E

E1E8EA0F-7620-4879-BA5D-33356568336E

E1E8EA0F-7620-4879-BA5D-33356568336E

E1E8EA0F-7620-4879-BA5D-33356568336E

事先早已安装好了。

于今大家修改大家的次序:将GetUserName改成TryGetUserName,将UserName以出口参数的款型反悔,Bool类型的再次回到值表示UserId是或不是存在,相信大家都会认为那是一个很广阔的API定义格局。

用上面包车型大巴指令安装,只需一些时日,它就会下载许多的文件,所及你要保险您的网络环境精美:

using System;

using System.Threading;

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;

namespace CachingCallHandler4OutParam

{

    class Program

    {

        static void Main(string[] args)

        {

            IMembershipService svc = PolicyInjection.Create<MembershipService, IMembershipService>();

            string userName;

            while (true)

            {

                svc.TryGetUserName("007", out userName);

                Console.WriteLine(userName);

                Thread.Sleep(1000);

            }

        }

    }

 

    public interface IMembershipService

    {

        bool TryGetUserName(string userId, out string userName);

    }

 

    public class MembershipService : IMembershipService

    {

        [CachingCallHandler]

        public bool TryGetUserName(string userId, out string userName)

        {

            userName = Guid.NewGuid().ToString();

            return true;

        }       

    }

}

sudo add-apt-repository ppa:webupd8team/java

运作方面一段程序之后,会抛出如下3个IndexOutOfRangeException,从StatckTrace我们得以领略,该尤其实际上是在将艺术调用再次来到消息转换来相应的出口参数是失误导致的:

sudo apt-get update

图片 1Stack
Trace:

sudo apt-get install oracle-java8-installer

at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(IMessage msg, Object[] outArgs, Object returnValue)

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at CachingCallHandler4OutParam.IMembershipService.TryGetUserName(String userId, String& userName)

at CachingCallHandler4OutParam.Program.Main(String[] args) in e:\EnterLib\CachingCallHandler4OutParam\CachingCallHandler4OutParam\Program.cs:line 15

at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

sudo apt-get install oracle-java8-set-default

② 、是何许导致至极的抛出?

用命令行安装的裨益是永不配置环境变量。

咱俩明天因而CachingCallHandler的Invoke方法的达成,能够看出有个别标题:该CallHander仅仅会缓存方法的重临值(this.AddToCache(key,
return2.ReturnValue);),而不是缓存输出参数;由于仅仅唯有重回值被缓存,所以最后创设的IMethodReturn不包括输出参数,从而造成再次回到的音讯与参数列表分裂等,导致至极的发生。

 

   1: public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)

   2: {

   3:     if (this.TargetMethodReturnsVoid(input))

   4:     {

   5:         return getNext()(input, getNext);

   6:     }

   7:     object[] inputs = new object[input.Inputs.Count];

   8:     for (int i = 0; i < inputs.Length; i++)

   9:     {

  10:         inputs[i] = input.Inputs[i];

  11:     }

  12:     string key = this.keyGenerator.CreateCacheKey(input.MethodBase, inputs);

  13:     object[] objArray2 = (object[])HttpRuntime.Cache.Get(key);

  14:     if (objArray2 == null)

  15:     {

  16:         IMethodReturn return2 = getNext()(input, getNext);

  17:         if (return2.Exception == null)

  18:         {

  19:             this.AddToCache(key, return2.ReturnValue);

  20:         }

  21:         return return2;

  22:     }

  23:     return input.CreateMethodReturn(objArray2[0], new object[] { input.Arguments });

  24: }

2、安装eclipse

③ 、难题怎样解决?

下载地址http://www.eclipse.org/downloads/,选择linux 32bit

今后大家来Fix那个Bug,让它援救出口参数并对出口参数和重临值一并缓存。为此,小编先是创立了之类3个OutputParamter类表示输出参数,属性Value和Index分别表示参数值和在格局参数列表中的地方:

双击eclipse就足以运转eclipse程序,运营的时候选择本身的workspace

   1: public class OutputParameter

   2: {

   3:     public object Value

   4:     { get; private set; }

   5:  

   6:     public int Index

   7:     { get; private set; }

   8:  

   9:     public OutputParameter(object value, int index)

  10:     {

  11:         this.Value = value;

  12:         this.Index = index;

  13:     }

  14: }

此时eclipse也固然安装实现了

下一场将供给实行缓存的艺术重临值和输出参数封装在二个单独的类中,小编将它起名为InvocationResult.
三个属性ReturnValue和Outputs分别代表重临值和输出参数。StreamlineArguments方法结合传入的之所以参数列表重回一个办法参数值的数组,该数组的成分顺序须求与方法的参数列表相匹配。

3、安装android-sdk

   1: public class InvocationResult

   2: {

   3:     public object ReturnValue

   4:     { get; private set; }

   5:  

   6:     public OutputParameter[] Outputs

   7:     { get; set; }

   8:  

   9:     public InvocationResult(object returnValue, OutputParameter[] outputs)

  10:     {

  11:         Guard.ArgumentNotNull(returnValue, "returnValue");

  12:         this.ReturnValue = returnValue;

  13:         if (null == outputs)

  14:         {

  15:             this.Outputs = new OutputParameter[0];

  16:         }

  17:         else

  18:         {

  19:             this.Outputs = outputs;

  20:         }

  21:     }

  22:  

  23:     public bool TryGetParameterValue(int index, out object parameterValue)

  24:     {

  25:         parameterValue = null;

  26:         var result = this.Outputs.Where(param => param.Index == index);

  27:         if (result.Count() > 0)

  28:         {

  29:             parameterValue = result.ToArray()[0].Value;

  30:             return true;

  31:         }

  32:         return false;

  33:     }

  34:  

  35:     public object[] StreamlineArguments(IParameterCollection arguments)

  36:     {

  37:         var list = new List<object>();

  38:         object paramValue;

  39:         for (int i = 0; i < arguments.Count; i++)

  40:         {

  41:             if (this.TryGetParameterValue(i, out paramValue))

  42:             {

  43:                 list.Add(paramValue);

  44:             }

  45:             else

  46:             {

  47:                 list.Add(arguments[i]);

  48:             }

  49:         }

  50:  

  51:         return list.ToArray();

  52:     }

  53: }

官方下载地址http://developer.android.com/sdk/index.html

下一场在现有CachingCallHandler的根基上,添加如下四个协理方法:AddToCache和GetInviocationResult,分别用于将InvocationResult对象参加缓存,以及基于IMethodInvocation和IMethodReturn对象创造InvocationResult对象。最终将类名改成FixedCachingCallHandler以示差距。

选择android-sdk_r24.3.4-linux.tgz

   1: public class FixedCachingCallHandler : ICallHandler

   2: {

   3:     //其他成员

   4:     private void AddToCache(string key, InvocationResult result)

   5:     {

   6:         HttpRuntime.Cache.Insert(key, result, null, Cache.NoAbsoluteExpiration, this.expirationTime, CacheItemPriority.Normal, null);

   7:     }

   8:  

   9:     

  10:     private InvocationResult GetInvocationResult(IMethodInvocation input, IMethodReturn methodReturn)

  11:     {

  12:         var outParms = new List<OutputParameter>();

  13:  

  14:         for (int i = 0; i < input.Arguments.Count; i++)

  15:         {

  16:             ParameterInfo paramInfo = input.Arguments.GetParameterInfo(i);

  17:             if (paramInfo.IsOut)

  18:             {

  19:                 OutputParameter param = new OutputParameter(input.Arguments[i], i);

  20:                 outParms.Add(param);

  21:             }

  22:         }

  23:  

  24:         return new InvocationResult(methodReturn.ReturnValue, outParms.ToArray());

  25:     }

  26:     

  27: }

下载好了之后双击打开,解压方式跟在此以前的jdk解压格局一样,不再重复

说到底我们重写Invoke方法,
去处对回到类型void的过滤,并落到实处对依照InvocationResult对象的缓存和取得:

在/root/.bashrc末尾行添加 

export ANDROID_HOME="/home/work/software/android-sdk-linux"
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
   1: public class FixedCachingCallHandler : ICallHandler

   2: {

   3:     //其他成员

   4:     public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)

   5:     {

   6:         object[] inputs = new object[input.Inputs.Count];

   7:         for (int i = 0; i < inputs.Length; i++)

   8:         {

   9:             inputs[i] = input.Inputs[i];

  10:         }

  11:         string key = this.keyGenerator.CreateCacheKey(input.MethodBase, inputs);

  12:         InvocationResult result = (InvocationResult)HttpRuntime.Cache.Get(key);

  13:         if (result == null)

  14:         {

  15:             IMethodReturn return2 = getNext()(input, getNext);

  16:             if (return2.Exception == null)

  17:             {

  18:                 this.AddToCache(key, this.GetInvocationResult(input, return2));

  19:             }

  20:             return return2;

  21:         }

  22:         return input.CreateMethodReturn(result.ReturnValue, result.StreamlineArguments(input.Arguments));

  23:  

  24:         return returnValue;

  25:     }

  26:  

  27:     private InvocationResult GetInvocationResult(IMethodInvocation input, IMethodReturn methodReturn)

  28:     {

  29:         var outParms = new List<OutputParameter>();

  30:  

  31:         for (int i = 0; i < input.Arguments.Count; i++)

  32:         {

  33:             ParameterInfo paramInfo = input.Arguments.GetParameterInfo(i);

  34:             if (paramInfo.IsOut)

  35:             {

  36:                 OutputParameter param = new OutputParameter(input.Arguments[i], i);

  37:                 outParms.Add(param);

  38:             }

  39:         }

  40:  

  41:         return new InvocationResult(methodReturn.ReturnValue, outParms.ToArray());

  42:     }    

  43: }

那时候这些sdk约等于一个软件管理器,假使要做android开发以来,至少要有二个android版本的,此时是空的,接下去在eclipse中安顿ADT插件

选取新的CachingCallHandler,你将会拿走不错的结果:

能够用命令行运维android :

4DD83AE8-070B-49df-9781-6F4673C85189

4DD83AE8-070B-49df-9781-6F4673C85189

4DD83AE8-070B-49df-9781-6F4673C85189

4DD83AE8-070B-49df-9781-6F4673C85189

4DD83AE8-070B-49df-9781-6F4673C85189
#android

作者:Artech
出处:http://artech.cnblogs.com
正文版权归小编和腾讯网共有,欢迎转发,但未经小编同意必须保留此段注明,且在篇章页面鲜明地点给出原来的书文连接,否则保留追究法律义务的职分。

 

4、安装adb(跟第叁步大概操作有点重复,不过为了清晰思路,浏览者能够忽略这一步)

1、下载android-sdk

二 、解压缩后放在某一个索引下,设置环境变量,在~/.bash_profile 或者
~/.bashrc文件中,

笔者是放在bashrc里的,加入一行

export PATH=${PATH}:<存放目录>/tools

叁 、运行android,下载android sdk tools | android sdk platform tools |
android sdk build-tools | android support repository | android support
library 那多少个文本。

chmod 777 <存放目录>/tools/adb    #莫不必要做这一步

叁 、连接上手提式有线电话机,通过极端,进入到tools目录下,第一遍执行,输入命令adb
kill-server。

四 、未来已经得以选择adb了。adb工具十二分好用,能够调试android手提式有线话机,下边是有的常用命令,可能会抽出来详细总括一篇文章介绍。

5、adb devices

6、adb root

7、adb shell

 

 

5、在eclipse中安装ADT

官方提供二种安装方式http://developer.android.com/sdk/eclipse-adt.html#installing,第2种是在线安装,第贰种是先下载安装包,然后用eclipse直接设置,两种艺术结果是同等的,在此推荐在线安装情势(当时在此地折腾了很久,安装的时候向来提示贫乏什么东西之类的,第①天突然又足以安装了,不可捉摸,希望读者能够1遍性安装成功!)

打开eclipse—>help—>Install New Software

点击work with前边的输入框前边的Add

在Name前面输入:ADT Plugin(能够随便起名)

在Location后边输入:https://dl-ssl.google.com/android/eclipse/

点击OK,行了,依据提醒,一步一步安装吧,中间会有提示是还是不是再一次启航eclipse,选择restart
now就行了。之后就配置OK了。

 

  

作者:chsry
出处:www.cnblogs.com/chsry
日期:2015-09-05-16:40:01
本博客文章,大多系个人整理开发,转载请注明出处

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图