美文网首页Android
Android Studio添加jar依赖

Android Studio添加jar依赖

作者: ThrowException | 来源:发表于2017-05-08 16:35 被阅读39次

    project/app/下新建一个目录libs,拷贝jar文件到project/app/libs目录下。

    方式一

    在jar文件上右键,选择Add As Library即可。

    这种方式比较适合jar比较少的情况,如果jar很多的话,每次添加jar都要这样子操作一次,太麻烦了。这时候就需要通过方式二来添加比较方便了。

    方式二

    project/app/build.gradle文件里面添加一行依赖

    apply plugin: 'com.android.application'
        android {
            compileSdkVersion 21
            buildToolsVersion '21.1.2'
            defaultConfig {
            applicationId "com.android...."
            minSdkVersion 9
            ....
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        productFlavors {
        }
       }
        
        dependencies {
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile fileTree(include: ['*.jar'], dir: 'libs') <--- here
    }
    

    注意事项:
    compile fileTree(include: ['*.jar'], dir: 'libs')必须放在其他依赖的后面,否则死活没效果,具体原因不清楚。
    参考:StackOverFlow:How to add any jar file in the Android studio?

    StackOverFlow-comment.png

    相关文章

      网友评论

        本文标题:Android Studio添加jar依赖

        本文链接:https://www.haomeiwen.com/subject/tvamtxtx.html