![](/img/trans.png)
[英]Android library with SyncAdapter not running in more than 1 app in the same phone
[英]How to add more build types in app than library
就像這里的示例一樣,我正在擴展我的構建類型以添加暫存:
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
}
staging {
initWith release
applicationIdSuffix '.staging'
}
}
}
但我也有一個依賴:
implementation project(':mylibrary')
編譯失敗,因為它不知道在:mylibrary
staging
與什么配對:
* What went wrong:
Could not determine the dependencies of task ':app:compileStagingJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:stagingCompileClasspath'.
> Could not resolve project :mylibrary.
Required by:
project :app
> Unable to find a matching configuration of project :mylibrary:
- Configuration 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'debugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'debug'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
- Configuration 'releaseApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'staging' and found incompatible value 'release'.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
- Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
這很公平,但我不能通過我所有的庫添加staging
只是為了獲得不同的應用程序后綴。
我試過了:
debugImplementation project(path: ':mylibrary', configuration: 'debug')
releaseImplementation project(path: ':mylibrary', configuration: 'release')
stagingImplementation project(path: ':mylibrary', configuration: 'release')
但它失敗了:
* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:releaseCompileClasspath'.
> Could not resolve project :mylibrary.
Required by:
project :app
> Project :app declares a dependency from configuration 'releaseImplementation' to configuration 'release' which is not declared in the descriptor for project :mylibrary.
debugImplementation project(path: ':mylibrary', configuration: 'default')
releaseImplementation project(path: ':mylibrary', configuration: 'default')
stagingImplementation project(path: ':mylibrary', configuration: 'default')
這可行,但每個版本都有庫的發布版本。 我不想要那個,我需要調試才能擁有調試版本的庫。
我見過這個 q ,但它是預先“ implementation
”並且publishNonDefault true
沒有效果,與上面的錯誤相同。
publishNonDefault 已被棄用,不再有效。 所有變體現已發布。
Gradlew 4.6 版
來過這里,做到了:P
您需要使用 Android Gradle 插件 3.0.0 指定matchingFallback
,以便插件知道在使用應用代碼編譯時要使用哪種回退構建類型的庫,以防在庫中找不到您的應用中定義的特定構建類型。
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
}
staging {
initWith release
applicationIdSuffix '.staging'
matchingFallbacks = ['release']
}
}
我也在我的react native 項目中創建了一個staging
buildType,構建很好,但由於某種原因它正在加載舊版本的應用程序。
在/android/app/build.gradle
文件中嘗試以下更改:
staging
更改為releaseStaging
我還不知道原因。 但這是使我的 react native 應用程序打開正確版本的應用程序的主要變化。
buildTypes {
...
releaseStaging {
initWith release
...
}
}
matchingFallbacks = ['release']
,就像@ahasbini提到的那樣。這修復了一些構建錯誤。
buildTypes {
...
releaseStaging {
initWith release
matchingFallbacks = ['release']
...
}
}
releaseStagingImplementation
,就像下面的代碼一樣。包含此內容后,我的應用程序在啟動時停止崩潰。
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
releaseStagingImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.