用Android studio依賴Library,gradle報錯問題

在本地依賴Library的時候gradle報這個   Error:Dependency Test:test_lib:unspecified on project app resolves to an APK archive which is not supported 錯誤,是因爲你新建的Lib,系統把他默認當成了一個Module了,就相當於你的ModuleA 去依賴一個 ModuleB。

解決辦法:把你的Lib的gradle裏面的這個

apply plugin: 'com.android.application'  
換成
apply plugin: 'com.android.library'  
就可以了。


還有一個問題就是有時會報  Error:Library projects cannot set applicationId. applicationId is set to 'com.example.test_lib' in default config. 這個錯誤,其實也很好解決,把Library的gradle配置的id去掉就好可以解決了

defaultConfig {
        applicationId "com.example.test_lib"  // 刪除此行
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

此錯誤的原因是
  1. 兩個AndroidManifest.xml的包名重複了
  2. 另外,Multiple dex files 的情況也有可能是有重複的support包,或者重複的jar


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章