如何在Android Studio的现有Android项目中包含java库

时间:2023-01-27 10:34:56

I want to include zxcvbn in my existing android project but unable to do it. Already try
How to import existing java project into android studio?
Android Studio: add project as library
Adding external Android and Java projects to Android projects in Android Studio

我想在我现有的android项目中包含zxcvbn但无法做到。已经尝试如何将现有的java项目导入android studio? Android Studio:将项目添加为库将外部Android和Java项目添加到Android Studio中的Android项目中

but no luck. According to my project requirements i will not use 'compile com.nulab-inc:zxcvbn:1.2.2' because i need source code in my project.

但没有运气。根据我的项目要求,我不会使用'compile com.nulab-inc:zxcvbn:1.2.2',因为我需要在我的项目中使用源代码。

My build.gradle

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '24.0.3'

    defaultConfig {
        applicationId "xx.xxx.xx"
        minSdkVersion 14
        targetSdkVersion 24

        // Enabling multidex support.
        multiDexEnabled true


    }

    dexOptions {

        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        abortOnError false
    }
    productFlavors {
    }
}
repositories {
    mavenCentral()
    maven { url 'http://guardian.github.com/maven/repo-releases' }
}
dependencies {
    compile files('libs/xx-3.0.2.jar')
    compile files('libs/xx-android-sdk-1.6.3.jar')

    compile project(':utilities')

    compile project(path: ':common')
    compile project(':common')

    compile 'com.google.http-client:google-http-client-gson:1.19.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.google.android.gms:play-services-base:9.0.2'
    compile 'com.google.android.gms:play-services-analytics:9.0.2'
    compile 'com.google.android.gms:play-services-wearable:9.0.2'
    compile 'com.google.android.gms:play-services-auth:9.0.2'
    compile 'com.google.apis:google-api-services-drive:v2-rev164-1.20.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.xx.xx:xx:1.2.2'
    compile 'com.x.x:x-compiler:1.2.2'
    compile 'com.x.x:x-v7:24.0.0'
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:cardview-v7:24.0.0'
    compile 'com.google.android.gms:play-services-appindexing:9.0.2'
}

android {
    useLibrary 'org.apache.http.legacy'
}

configurations {
    all*.exclude group: 'com.google.guava', module: 'guava-jdk5'
}

1 个解决方案

#1


2  

You should import as new module for your android project follow the below steps to add as a new module

您应该为您的Android项目导入新模块,按照以下步骤添加为新模块

 1.Go to file -> New - > Import Module

and select your zxcvbn library location path and click finish. This will add a new module to your existing android project.

并选择您的zxcvbn库位置路径,然后单击“完成”。这将为您现有的Android项目添加一个新模块。

Then you should add a new module i,e your ( zxcvbn library ) to your project dependency to do that

然后你应该添加一个新的模块i,你的(zxcvbn库)到你的项目依赖项来做到这一点

 2.Click project structure options - > dependency select your  zxcvbn library and click ok and synch project

Now your java library included in your android project

现在你的java库包含在你的android项目中

#1


2  

You should import as new module for your android project follow the below steps to add as a new module

您应该为您的Android项目导入新模块,按照以下步骤添加为新模块

 1.Go to file -> New - > Import Module

and select your zxcvbn library location path and click finish. This will add a new module to your existing android project.

并选择您的zxcvbn库位置路径,然后单击“完成”。这将为您现有的Android项目添加一个新模块。

Then you should add a new module i,e your ( zxcvbn library ) to your project dependency to do that

然后你应该添加一个新的模块i,你的(zxcvbn库)到你的项目依赖项来做到这一点

 2.Click project structure options - > dependency select your  zxcvbn library and click ok and synch project

Now your java library included in your android project

现在你的java库包含在你的android项目中