2016-12-15 90 views
1

現有的Android項目,我想在我現有的Android項目zxcvbn但無法做到這一點。 已經嘗試
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如何包含java庫在Android Studio中

,但沒有運氣。根據我的項目要求,我不會使用'compile com.nulab-inc:zxcvbn:1.2.2'因爲我需要在我的項目中使用源代碼。

我的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' 
} 
+0

你需要'mavenCentral( )'如在文件的gradle @ –

+0

一個cricket_007 repostiory:在zxcvbn4j /的build.gradle(https://github.com/nulab/zxcvbn4j/blob/master/build.gradle)mavenCentral()是一提。在我的項目gradle mavenCentral()中也提到。 – nikhil

+0

請出示您的gradle這個文件 - 不要緊,在你掛 –

回答

2

你應該導入爲新的模塊,爲您的Android項目按照以下步驟添加爲一個新的模塊

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

,並選擇您的zxcvbn庫的位置和路徑點擊完成。這將爲您的現有Android項目添加一個新模塊。

就應該添加一個新的模塊I,E您(zxcvbn庫)到您的項目依賴這樣做

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

現在包含在你的Android項目中的Java庫

+0

我已經嘗試這一點,但它不能正常工作。當我點zxcvbn文件夾比Android Studio顯示消息「請提供模塊」,如果我指向build.gradle比它的導入只gradle文件格式不正確。 – nikhil

+0

你應該指向根文件夾不僅沒有的build.gradle不是由Android工作室接受的文件 –

+0

... – nikhil

相關問題