Flutter 应用程序在 Android 模拟器上运行,但不在物理设备上(OnePlus 7T)

Posted

技术标签:

【中文标题】Flutter 应用程序在 Android 模拟器上运行,但不在物理设备上(OnePlus 7T)【英文标题】:Flutter app is running on Android Emulator but not on Physical Device (OnePlus 7T) 【发布时间】:2020-07-15 15:39:52 【问题描述】:

当我在 android 模拟器上运行我的颤振应用程序时,它运行时没有错误,但是当我在移动设备上运行它时,它在调试控制台中显示以下错误:

在调试模式下在 HD1901 上启动 lib\main.dart... FAILURE:构建失败并出现异常。

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Failed to transform artifact 'arm64_v8a_debug.jar (io.flutter:arm64_v8a_debug:1.0.0-af51afceb8886cc11e25047523c4e0c7e1f5d408)' to match attributes artifactType=android-classes, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime.

      > Execution failed for JetifyTransform: C:\Users\Bharat\.gradle\caches\modules-2\files-2.1\io.flutter\arm64_v8a_debug\1.0.0-af51afceb8886cc11e25047523c4e0c7e1f5d408\b829535c84919575c5e7bfe4ebb08763a01eceec\arm64_v8a_debug-1.0.0-af51afceb8886cc11e25047523c4e0c7e1f5d408.jar.

         > Failed to transform 'C:\Users\Bharat\.gradle\caches\modules-2\files-2.1\io.flutter\arm64_v8a_debug\1.0.0-af51afceb8886cc11e25047523c4e0c7e1f5d408\b829535c84919575c5e7bfe4ebb08763a01eceec\arm64_v8a_debug-1.0.0-af51afceb8886cc11e25047523c4e0c7e1f5d408.jar' using Jetifier. Reason: invalid entry size (expected 27494264 but got 27496386 bytes). (Run with --stacktrace for more details.)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 48s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

“颤振医生 -v”与设备连接的输出:

[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.720], locale en-IN)
    • Flutter version 1.12.13+hotfix.9 at C:\src\flutter
    • Framework revision f139b11009 (4 days ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\Bharat\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = C:\Users\Bharat\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 43.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code (version 1.43.2)
    • VS Code at C:\Users\Bharat\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.8.1

[√] Connected device (1 available)
    • HD1901 • 90801aca • android-arm64 • Android 10 (API 29)

• No issues found!

应用级“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.")


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"

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.bbayshop_app"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    buildTypes 
        release 
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        
    


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'

项目级“build.gradle”文件的内容:

buildscript 
    ext.kotlin_version = '1.3.50'
    repositories 
        google()
        jcenter()
    

    dependencies 
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    


allprojects 
    repositories 
        google()
        jcenter()
    


rootProject.buildDir = '../build'
subprojects 
    project.buildDir = "$rootProject.buildDir/$project.name"

subprojects 
    project.evaluationDependsOn(':app')


task clean(type: Delete) 
    delete rootProject.buildDir

还包括“gradle-wrapper.properties”文件的内容:

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

【问题讨论】:

在连接设备的情况下发布您的“flutter doctor -v” @MarianoZorrilla 感谢您的回复。我已经在连接设备的情况下发布了“flutter doctor -v”的输出。 看起来可能是缓存构建的问题。在您的设备上运行之前,您是否尝试过“flutter clean”? @MarianoZorrilla 是的,我试过了,但仍然是同样的错误。请帮助:( 您是否在项目中添加了库?也发布您的应用级 build.gradle 文件 【参考方案1】:

已解决,只需删除位于 C:\Users\.gradle\ 的“.gradle”文件夹中的所有内容 如果显示文件已打开且无法删除,只需打开任务管理器,转到详细信息选项卡并找到“java.exe” 右键单击每个“java.exe”,然后单击“结束进程树”。所有java.exe进程结束后,返回“.gradle”文件夹并删除所有内容。 而已。 :)

【讨论】:

以上是关于Flutter 应用程序在 Android 模拟器上运行,但不在物理设备上(OnePlus 7T)的主要内容,如果未能解决你的问题,请参考以下文章

Flutter:正在运行/调试应用程序-> 黑屏并且无法在屏幕表面上包裹 Android 模拟器

如何在开发过程中同时使用 Android 和 IOS 模拟器来测试我的 Flutter 应用程序?

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

Flutter 应用程序在 Android 模拟器上运行,但不在物理设备上(OnePlus 7T)

Flutter 应用程序:IOS 模拟器未连接到 Android Studio

升级到 Flutter 到 2.5.0 后,无法从 Android Studio 的 iOS 模拟器运行应用程序