我正在尝试从flutter应用程序制作apk,因此在创建flutter项目之后:
flutter create release_app_test
根据official网站,我创建了一个签名密钥。
这是一个完整的构建过程:
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.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.release_app_test"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
我通过以下命令制作了apk:
tazik@mx-linux:/mnt/Project/Flutter/my_practises/release_app_test
$ flutter build apk --split-per-abi
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 11.4s
✓ Built build/app/outputs/apk/release/app-armeabi-v7a-release.apk (5.1MB).
✓ Built build/app/outputs/apk/release/app-arm64-v8a-release.apk (5.4MB).
✓ Built build/app/outputs/apk/release/app-x86_64-release.apk (5.6MB).
tazik@mx-linux:/mnt/Project/Flutter/my_practises/release_app_test
$
现在创建apk之后,我想通过adb命令安装它,但出现此错误:
tazik@mx-linux:/mnt/Software/Linux/Android/SDK/platform-tools
$ adb install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-x86_64-release.apk
Performing Streamed Install
adb: failed to install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-x86_64-release.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
tazik@mx-linux:/mnt/Software/Linux/Android/SDK/platform-tools
$ adb install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
Performing Streamed Install
adb: failed to install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-armeabi-v7a-release.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
tazik@mx-linux:/mnt/Software/Linux/Android/SDK/platform-tools
$ adb install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-arm64-v8a-release.apk
Performing Streamed Install
adb: failed to install /mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release/app-arm64-v8a-release.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
tazik@mx-linux:/mnt/Software/Linux/Android/SDK/platform-tools
未安装任何APK。
谷歌搜索后,我将其添加到模块build.gradle并在Android块内
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'x86_64'
universalApk true
}
}
添加此脚本后,我得到了以下结果:
tazik@mx-linux:/mnt/Project/Flutter/my_practises/release_app_test
$ flutter build apk --split-per-abi
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Removed unused resources: Binary resource data reduced from 44KB to 35KB: Removed 20%
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 13.6s
✓ Built build/app/outputs/apk/release/app-armeabi-v7a-release.apk (5.1MB).
✓ Built build/app/outputs/apk/release/app-x86_64-release.apk (5.6MB).
tazik@mx-linux:/mnt/Project/Flutter/my_practises/release_app_test
内置的apk:
tazik@mx-linux:/mnt/Project/Flutter/my_practises/release_app_test/build/app/outputs/apk/release
$ ls -l --block-size=MB
total 28MB
-rwxrwxrwx 1 root root 6MB Apr 28 12:25 app-armeabi-v7a-release.apk
-rwxrwxrwx 1 root root 16MB Apr 28 12:25 app-universal-release.apk
-rwxrwxrwx 1 root root 6MB Apr 28 12:25 app-x86_64-release.apk
-rwxrwxrwx 1 root root 1MB Apr 28 12:25 app-x86-release.apk
-rwxrwxrwx 1 root root 1MB Apr 28 12:25 output.json
仅安装了app-x86-release.apk,但它已损坏且无法在模拟器上运行。因为您可以看到它的大小为1MB。
我的Flutter SDK版本是: flutter_linux_v1.12.13 + hotfix.9-stable
答案 0 :(得分:0)
截至目前,通过在Android仿真器中拖放来安装Flutter Release Fat apk,我们遇到了一些问题。
但是,您可以通过生成支持的ABI及其对应的模拟器进行检查。我没有尝试过,但是如果您需要的话,可以尝试一下。可以在下面的链接中找到详细信息。