我正在設置一個Android庫與不同的productFlavors。 圖書館有光和全味道。該文件被正確地設置好的了:未能在庫中使用productFlavors導入android支持v4或v7
src/main/java/com/example/...
主類
src/full/java/com/example/...
全類
src/light/java/com/example/...
光類
Android Studio中正確地理解這一點,增加了(full)
到韻味十足。
問題:像okhttp
這樣的依賴項按預期工作,但不是appcompat-v7
。使用ViewPager
,FragmentActivity
,RecyclerView
一切。我試着加入依賴於fullCompile
,但它也不能工作。的依賴是不是由Android工作室解決,進口不工作,除了確定okhttp
,exoplayer
等。
我試過Invalidate Cache/Restart
,clean Project
,Resync gradle
,沒有工作。
圖書館build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
...
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
publishNonDefault true
productFlavors {
full {
}
light {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
fullCompile 'com.android.support:support-v4:23.1.1'
fullCompile 'com.android.support:appcompat-v7:23.1.1'
fullCompile 'com.android.support:recyclerview-v7:23.1.1'
fullCompile 'com.squareup.picasso:picasso:2.5.0'
}
應用build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildTypes {
release {
}
}
productFlavors {
full {
}
light {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:support-v4:23.+'
compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
fullCompile project(path: ':library', configuration: 'fullRelease')
lightCompile project(path: ':library', configuration: 'lightRelease')
}
你能提供在gradle中產生的錯誤嗎? – droidpl
生成應用程序時,它會顯示錯誤:(1073,64)錯誤:軟件包ViewPager不存在。如果我瀏覽這些類,則「ViewPager」導入不會被解析並導致該類中的錯誤。 @droidpl –
如果你在某個地方使用viewPager,並且這個類不在相應的src/light或者src/full文件夾的完整/光照版本中,那麼它將不會被導入,因爲你在這個版本中使用了fullCompile圖書館可用。你能重新檢查這個文件崩潰的地方嗎? – droidpl