Flutter:Android模拟器上未安装发布apk

Posted

技术标签:

【中文标题】Flutter:Android模拟器上未安装发布apk【英文标题】:Flutter: release apk are not installed on android emulator 【发布时间】:2020-08-11 23:35:33 【问题描述】:

我正在尝试从 Flutter 应用程序中制作 apk,所以在创建 Flutter 项目之后:

flutter create release_app_test

根据official 站点,我创建了一个签名密钥。

这是一个完整的构建 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.")


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

【问题讨论】:

【参考方案1】:

截至目前,我们在通过在 android 模拟器中拖放来安装颤振释放脂肪 apk 时遇到了一些问题。

但是,您可以通过生成支持的 ABI 及其相应的模拟器来进行检查。我没试过,但如果你最多需要的话,你可以试一试。详细信息可以在下面的链接中找到。

flutter issues

【讨论】:

这个问题不是模拟器的问题,我不能在真实设备上安装这个apk @RaguSwaminathan 那么 APK 可能已损坏,或者您需要在您的手机中启用某些开发人员选项,例如“启用从未知来源安装”。

以上是关于Flutter:Android模拟器上未安装发布apk的主要内容,如果未能解决你的问题,请参考以下文章

IOS 模拟器上未处理的电话号码

Flutter 本地通知在 IOS 上未按预期工作

模拟器上未收到 Firebase 消息

在 Android 设备上未调用 onLocationChanged()

在 android 中关闭应用程序时,在真实设备上未收到一个信号通知

无法安装请求的应用程序 - Flutter