【发布时间】:2020-09-18 15:48:04
【问题描述】:
我在模块级 gradle 文件中设置了自定义 outputFileName。当我尝试通过按下播放按钮(或使用 debu/release 构建的菜单命令)来运行应用程序时,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'
}
【问题讨论】:
-
你能分享
flutter doctor的输出吗? -
@SanjaySharma "医生总结(要查看所有详细信息,请运行 flutter doctor -v):[√] Flutter(通道稳定,v1.12.13+hotfix.9,在 Microsoft Windows [版本 10.0.18363.657 ], locale en-IN) [√] Android 工具链 - 为 Android 设备开发 (Android SDK 版本 29.0.3) [√] Android Studio (版本 3.6) [√] VS Code (版本 1.45.1) [√] 连接的设备(1 个可用) • 未发现问题!”
标签: android flutter gradle groovy