AAR 工件没有构建变体后缀
AAR artifact does not have build variant suffix
这很奇怪,我已经敲了一天的脑袋,因为这不是默认行为。
我有一个 AAR 项目和模块。它是另一个项目的简化复制和粘贴。默认情况下,Android Studio 将输出文件名为 module-build_variant.aar[=13= 的 AAR 文件]
然而,当我构建这个时,它是 module.aar。奇怪。
郑重声明,我尝试用谷歌搜索问题,从命令行构建,仔细研究 build.gradle 文件。纳达.
我希望这个项目像其他项目一样构建并正确命名 AAR 文件。
项目build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: '../sharedConf/versions.gradle'
addRepos(repositories)
dependencies {
classpath deps.android_gradle_plugin
classpath deps.kotlin_plugin
}
}
allprojects {
addRepos(repositories)
}
task clean(type: Delete) {
delete rootProject.buildDir
模块build.gradle
// Import shared gradle settings
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
// Every shared preference among the Android projects
def versionPropsFile = file('../../sharedConf/versions.gradle')
if (!versionPropsFile.canRead()) {
throw new GradleException('versions.gradle doesnt exist')
}
compileSdkVersion build_versions.target_sdk
buildToolsVersion build_versions.build_tools
// The version of the product. Generated by the build.py script
String version = build_versions.version_name
if (project.hasProperty("ms_version")) {
version = "$ms_version"
}
defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionName version.trim()
versionCode build_versions.version_code
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
abortOnError true
}
signingConfigs {
release {
<SNIP>
}
}
sourceSets {
main.java.srcDirs += '../../***/***/src/main/java'
main.java.srcDirs += '../../Infra/infra/src/main/java'
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation deps.kotlin_stdlib
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
implementation 'androidx.preference:preference:1.1.0-alpha04'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// OK_HTTP_3
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
}
versions.gradle
def versions = [:]
versions.android_gradle_plugin = "3.3.2"
versions.kotlin = "1.3.21"
def build_versions = [:]
build_versions.version_name = "7.0"
build_versions.version_code = 7
build_versions.min_sdk = 16
build_versions.target_sdk = 29
build_versions.build_tools = "29.0.2"
ext.build_versions = build_versions
def deps = [:]
deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
deps.kotlin_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
deps.kotlin_stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
ext.deps = deps
def addRepos(RepositoryHandler handler) {
handler.google()
handler.jcenter()
handler.mavenCentral()
handler.flatDir {
dirs 'libs'
}
}
ext.addRepos = this.&addRepos
如果非要我猜的话,在某些情况下 AS 会构建一个 AAR。也许它正在合并构建变体(尝试调试 minified=false)或类似的东西。
原因是 gradle-wrapper.properties 中的版本不正确。
本项目是5.4.1。当恢复到 4.10.1 时,它会正确生成。
请注意,我在这里以最松散、最不准确的方式使用 不正确。我没有收到错误或通知。功能只是改变了。您会期望 gradle 和 gradle 插件的不匹配会破坏构建。
这很奇怪,我已经敲了一天的脑袋,因为这不是默认行为。
我有一个 AAR 项目和模块。它是另一个项目的简化复制和粘贴。默认情况下,Android Studio 将输出文件名为 module-build_variant.aar[=13= 的 AAR 文件]
然而,当我构建这个时,它是 module.aar。奇怪。
郑重声明,我尝试用谷歌搜索问题,从命令行构建,仔细研究 build.gradle 文件。纳达.
我希望这个项目像其他项目一样构建并正确命名 AAR 文件。
项目build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: '../sharedConf/versions.gradle'
addRepos(repositories)
dependencies {
classpath deps.android_gradle_plugin
classpath deps.kotlin_plugin
}
}
allprojects {
addRepos(repositories)
}
task clean(type: Delete) {
delete rootProject.buildDir
模块build.gradle
// Import shared gradle settings
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
// Every shared preference among the Android projects
def versionPropsFile = file('../../sharedConf/versions.gradle')
if (!versionPropsFile.canRead()) {
throw new GradleException('versions.gradle doesnt exist')
}
compileSdkVersion build_versions.target_sdk
buildToolsVersion build_versions.build_tools
// The version of the product. Generated by the build.py script
String version = build_versions.version_name
if (project.hasProperty("ms_version")) {
version = "$ms_version"
}
defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionName version.trim()
versionCode build_versions.version_code
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
abortOnError true
}
signingConfigs {
release {
<SNIP>
}
}
sourceSets {
main.java.srcDirs += '../../***/***/src/main/java'
main.java.srcDirs += '../../Infra/infra/src/main/java'
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation deps.kotlin_stdlib
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
implementation 'androidx.preference:preference:1.1.0-alpha04'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// OK_HTTP_3
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
}
versions.gradle
def versions = [:]
versions.android_gradle_plugin = "3.3.2"
versions.kotlin = "1.3.21"
def build_versions = [:]
build_versions.version_name = "7.0"
build_versions.version_code = 7
build_versions.min_sdk = 16
build_versions.target_sdk = 29
build_versions.build_tools = "29.0.2"
ext.build_versions = build_versions
def deps = [:]
deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
deps.kotlin_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
deps.kotlin_stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
ext.deps = deps
def addRepos(RepositoryHandler handler) {
handler.google()
handler.jcenter()
handler.mavenCentral()
handler.flatDir {
dirs 'libs'
}
}
ext.addRepos = this.&addRepos
如果非要我猜的话,在某些情况下 AS 会构建一个 AAR。也许它正在合并构建变体(尝试调试 minified=false)或类似的东西。
原因是 gradle-wrapper.properties 中的版本不正确。
本项目是5.4.1。当恢复到 4.10.1 时,它会正确生成。
请注意,我在这里以最松散、最不准确的方式使用 不正确。我没有收到错误或通知。功能只是改变了。您会期望 gradle 和 gradle 插件的不匹配会破坏构建。