我已经在模块级gradle文件中设置了自定义outputFileName。当我尝试通过按播放按钮(或使用菜单命令进行构建/释放构建)运行应用程序时,正在构建apk,但未在连接的设备上安装该应用程序。
出现以下错误。
已完成错误:Gradle构建无法生成.apk文件。该文件可能是在C:\ Users \ BnayA \ Work \ Office \ sangrahapp \ build下生成的,但该工具找不到它。
我为此搜索了解决方案,但没有任何帮助我对其进行修复。
下面是我的应用/模块级别的Gradle配置。
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
ant.condition(property: 'os', value: 'windows') {
os(family: 'windows')
}
ant.condition(property: 'os', value: 'unix') {
os(family: 'unix')
}
// Based on http://stackoverflow.com/questions/17097263#24121734
def getMasterCommitCount = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'rev-list', '--first-parent', '--count', 'master'
break
case 'unix':
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
break
}
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
} catch (ignored) {
return -1
}
}
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
switch (ant.properties.os) {
case 'windows':
commandLine 'cmd', '/c', 'git', 'describe', '--tags', '--dirty', '--always'
break
case 'unix':
commandLine 'git', 'describe', '--tags', '--dirty', '--always'
break
}
standardOutput = stdout
}
return stdout.toString().trim()
} catch (ignored) {
return null
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "abc.def.ghi"
minSdkVersion 21
targetSdkVersion 29
versionCode getMasterCommitCount()
versionName getVersionName()
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
archivesBaseName = 'abc'
}
buildTypes {
debug {
applicationIdSuffix '.debug'
versionNameSuffix '_debug'
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk"))
}
}
splits {
abi {
universalApk true
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
}
答案 0 :(得分:0)
尝试替换
outputFileName = new File(outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk"))
具有以下代码
outputFileName = new File(
output.outputFile.parent,
outputFileName.replace(".apk", "-${defaultConfig.versionName}.apk"))
更新: 取代这个
splits {
abi {
universalApk true
}
}
带有以下内容
splits {
abi {
enable true
reset()
universalApk false
}
}
也请在debug
中添加签名配置。
signingConfig signingConfigs.debug