![](/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.