a_s*_*ber 16 android-studio android-studio-3.0
当我使用Android Studio 3.0并使用下一版本的build:gradle in project/build.gradle:
classpath 'com.android.tools.build:gradle:3.0.1'
Run Code Online (Sandbox Code Playgroud)
它工作正常.我更新到Android Studio 3.1后,结果我更新build:gradle:
classpath 'com.android.tools.build:gradle:3.1.0'
Run Code Online (Sandbox Code Playgroud)
现在我的错误在于app/build.gradle:
def releaseFileName = "${rootProject.name}_${defaultConfig.versionName}.apk"
outputFileName = new File(rootProject.projectDir.absolutePath + "/release", releaseFileName.toLowerCase())
Run Code Online (Sandbox Code Playgroud)
错误:
设置输出文件名时不支持绝对路径
我需要将输出apk(app-release.apk)放在项目的特定路径中.在文件夹中MyProject/release/app-relese.apk.我怎么能这样做?
小智 24
为了防止这种情况发生,这个错误意味着现在不允许在与apk文件名相关的任何内容上使用绝对路径.我可以在我之前和之后附上你以实现我所需要的(在项目/ app/build /文件夹中拥有APK:
在gradle 3.1.0之前
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = new File(
output.outputFile.parent,
output.outputFile.name)
}
}
Run Code Online (Sandbox Code Playgroud)
IN或AFTER gradle 3.1.0
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = new File(
"./../../../../../build/",
output.outputFile.name)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 15
我认为使用"./../../../"是一个糟糕的解决方案......我对几个项目使用通用的gradle脚本,我想让代码从输出dir的深度独立.
经过一番研究后,我找到了gradle插件3.1.2的解决方案:
applicationVariants.all { variant ->
variant.outputs.all { output ->
def relativeRootDir = output.packageApplication.outputDirectory.toPath()
.relativize(rootDir.toPath()).toFile()
output.outputFileName = new File( "$relativeRootDir/release", newOutputName)
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题.我没有努力弄清楚究竟发生了什么,但有一个简单的解决方法.
只需从新文件中删除root并信任该框架,即将代码更改为
outputFileName = new File("release", releaseFileName.toLowerCase())
Run Code Online (Sandbox Code Playgroud)
这对我们来说已经足够了.我们不关心apk的位置,只关注特定风味的apk的名称.
组合/连接您的新文件名:
def newFileName = "assemble-your-new-file-name"
Run Code Online (Sandbox Code Playgroud)
然后,只需将其分配回去。
outputFileName = newFileName
Run Code Online (Sandbox Code Playgroud)
更具体如下
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
// Redirect your apks to new defined location to outputDirPath
def outputDirPath = new File("${project.rootDir.absolutePath}/apks/${variant.flavorName}/${variant.buildType.name}")
variant.packageApplicationProvider.get().outputDirectory = outputDirPath
def apkFileName = "${rootProject.name}_${android.defaultConfig.versionName}.apk"
output.outputFileName = apkFileName // directly assign the new name back to outputFileName
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14130 次 |
| 最近记录: |