android studio 如何导入第三方jar包
2016-07-21 10:05
555 查看
版本:android stuido 2.2
用于测试的jar包叫sdktest.jar 它的实现很简单,一个类,两个方法:
把这个jar包拷贝到app/libs目录下,然后打开build.gradle,会看到:
其中compile fileTree(include: [‘*.jar’], dir: ‘libs’)说明从工程级对这个jar包的依赖路径已经指明了,所以这里不需要再做额外的配置。
切换到project视图,已经可以看到这个jar包了
到这里还没有,还要把这个jar包设置成add as library
![](https://img-blog.csdn.net/20160721100334001)
然后就可以在工程中使用了:
用于测试的jar包叫sdktest.jar 它的实现很简单,一个类,两个方法:
public class SDKTest2 { private static final String TAG = "SDKTest2"; public SDKTest2() { } public void testFunc1(String str1) { Log.i("SDKTest2", str1); } public int testFunc2(int a) { return a; } }
把这个jar包拷贝到app/libs目录下,然后打开build.gradle,会看到:
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4' testCompile 'junit:junit:4.12' compile files('libs/sdktest.jar') }
其中compile fileTree(include: [‘*.jar’], dir: ‘libs’)说明从工程级对这个jar包的依赖路径已经指明了,所以这里不需要再做额外的配置。
切换到project视图,已经可以看到这个jar包了
到这里还没有,还要把这个jar包设置成add as library
然后就可以在工程中使用了:
mBtnTest = (Button) findViewById(R.id.button); final SDKTest2 test2 = new SDKTest2(); mBtnTest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { test2.testFunc1("hello world"); int a = test2.testFunc2(123); System.out.println(a); } });
相关文章推荐
- Android Selector使用案例
- Android学习路线图
- Android学习路线图
- Android学习路线图
- Android堆栈分析
- Android动画之逐帧动画
- Android Studio创建的Android项目一般需要忽略
- geekband android #5 第一周分享(初识Android)
- android studio入门
- About Location of the android sdk has not been setup in the preferences
- 安卓端打电话和发送短信
- android命名规范
- 如何在mac本上安装android sdk
- MaterialDesign设计风格之自定义toolbar的简单实现
- Android Studio快捷键
- 详解Android中AsyncTask的使用
- Android studio中.so文件的提交
- Android的两种上下文的区别
- Android Studio 使用Gradle引入第三方库文件的总结
- Android学习进阶和IoC