android - Flutter .apk 已构建但未安装在设备/模拟器中
问题描述
我在模块级 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'
}
解决方案
尝试更换
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
推荐阅读
- ios - 尽管没有在表格视图中实现尾随滑动动作,但删除按钮会在滑动时自动实现
- c++ - Opencv 断言错误
- ios - 试图在一个视图控制器中获取两个 UICollection 视图。只有一个出现
- jenkins - 在 Jenkinsfile (Groovy) 中获取给定文件夹中的文件名列表
- c# - 使用条款属性来控制每个项目栏的选择
- protractor - 在量角器测试中设置 chrome 扩展路径
- c# - POST 到 vsts 在 C# 中发布 api 端点
- excel - 在 Excel 中创建新选项卡
- angular - 在托盘中显示通知图像和应用程序图标,同时使用 FCM firebase 插件进行通知
- sql - 在 VB.NET 中使用 LINQ Lambda 在 WHERE 之后选择