使用 USB 电缆调试时 Gradle 任务 assembleDebug 失败
Posted
技术标签:
【中文标题】使用 USB 电缆调试时 Gradle 任务 assembleDebug 失败【英文标题】:Gradle task assembleDebug failed when debugging with USB-cable 【发布时间】:2021-10-11 15:53:48 【问题描述】:我刚刚安装了android studio和vscode开始学习flutter。 因此,当我尝试在(chrome)上运行演示应用程序时,该应用程序运行良好,但是当尝试使用 USB 电缆在我的手机上进行调试时,它会失败。 我有一台旧电脑,无法使用模拟器
试过flutter run -v
它给了我这个:
[ +25 ms] Building APK
[ +70 ms] Running Gradle task 'assembleDebug'...
[ +14 ms] Using gradle from C:\Users\hh\StudioProjects\untitled\android\gradlew.bat.
[ +48 ms] executing: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ +206 ms] Exit code 0 from: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ ] openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
OpenJDK 64-Bit Server VM (build 11.0.10+0-b96-7249189, mixed mode)
[ +3 ms] executing: [C:\Users\hh\StudioProjects\untitled\android/] C:\Users\hh\StudioProjects\untitled\android\gradlew.bat -Pverbose=true
-Ptarget-platform=android-arm64 -Ptarget=C:\Users\hh\StudioProjects\untitled\lib\main.dart -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
-Pdart-obfuscation=false -Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
[+12814 ms] Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
[+123489 ms] FAILURE: Build failed with an exception.
[ +27 ms] * What went wrong:
[ ] A problem occurred configuring root project 'android'.
[ ] > Could not resolve all artifacts for configuration ':classpath'.
[ ] > Could not find gradle-4.1.0.jar (com.android.tools.build:gradle:4.1.0).
[ +10 ms] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar
[ +19 ms] > Could not find builder-4.1.0.jar (com.android.tools.build:builder:4.1.0).
[ +47 ms] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.1.0/builder-4.1.0.jar
[ ] > Could not find aaptcompiler-4.1.0.jar (com.android.tools.build:aaptcompiler:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/aaptcompiler/4.1.0/aaptcompiler-4.1.0.jar
[ ] > Could not find bundletool-0.14.0.jar (com.android.tools.build:bundletool:0.14.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.14.0/bundletool-0.14.0.jar
[ ] > Could not find manifest-merger-27.1.0.jar (com.android.tools.build:manifest-merger:27.1.0).
[ +1 ms] Searched in the following locations:
[ +4 ms] https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/27.1.0/manifest-merger-27.1.0.jar
[ ] > Could not find lint-gradle-api-27.1.0.jar (com.android.tools.lint:lint-gradle-api:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-gradle-api/27.1.0/lint-gradle-api-27.1.0.jar
[ ] > Could not find lint-model-27.1.0.jar (com.android.tools.lint:lint-model:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-model/27.1.0/lint-model-27.1.0.jar
[ ] > Could not find sdk-common-27.1.0.jar (com.android.tools:sdk-common:27.1.0).
[ ] Searched in the following locations:
[ +28 ms] https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/27.1.0/sdk-common-27.1.0.jar
[ ] > Could not find aapt2-proto-4.1.0-6503028.jar (com.android.tools.build:aapt2-proto:4.1.0-6503028).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-proto/4.1.0-6503028/aapt2-proto-4.1.0-6503028.jar
[ ] > Could not find crash-27.1.0.jar (com.android.tools.analytics-library:crash:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/crash/27.1.0/crash-27.1.0.jar
[ ] > Could not find gradle-api-4.1.0.jar (com.android.tools.build:gradle-api:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-api/4.1.0/gradle-api-4.1.0.jar
[ ] > Could not find databinding-compiler-common-4.1.0.jar (androidx.databinding:databinding-compiler-common:4.1.0).
[ ] Searched in the following locations:
[ +3 ms] https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-compiler-common/4.1.0/databinding-compiler-common-4.1.0.jar
[ +4 ms] > Could not find builder-model-4.1.0.jar (com.android.tools.build:builder-model:4.1.0).
[ +13 ms] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/4.1.0/builder-model-4.1.0.jar
[ ] > Could not find builder-test-api-4.1.0.jar (com.android.tools.build:builder-test-api:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-test-api/4.1.0/builder-test-api-4.1.0.jar
[ ] > Could not find ddmlib-27.1.0.jar (com.android.tools.ddms:ddmlib:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/ddms/ddmlib/27.1.0/ddmlib-27.1.0.jar
[ +50 ms] > Could not find signflinger-4.1.0.jar (com.android:signflinger:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/signflinger/4.1.0/signflinger-4.1.0.jar
[ ] > Could not find zipflinger-4.1.0.jar (com.android:zipflinger:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/zipflinger/4.1.0/zipflinger-4.1.0.jar
[ ] > Could not find tracker-27.1.0.jar (com.android.tools.analytics-library:tracker:27.1.0).
[ ] Searched in the following locations:
[ +1 ms] https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/tracker/27.1.0/tracker-27.1.0.jar
[ ] > Could not find sdklib-27.1.0.jar (com.android.tools:sdklib:27.1.0).
[ +10 ms] Searched in the following locations:
[ +6 ms] https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/27.1.0/sdklib-27.1.0.jar
[ ] > Could not find layoutlib-api-27.1.0.jar (com.android.tools.layoutlib:layoutlib-api:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/layoutlib/layoutlib-api/27.1.0/layoutlib-api-27.1.0.jar
[ ] > Could not find dvlib-27.1.0.jar (com.android.tools:dvlib:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/dvlib/27.1.0/dvlib-27.1.0.jar
[ ] > Could not find repository-27.1.0.jar (com.android.tools:repository:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/repository/27.1.0/repository-27.1.0.jar
[ +7 ms] > Could not find shared-27.1.0.jar (com.android.tools.analytics-library:shared:27.1.0).
[ +8 ms] Searched in the following locations:
[ +1 ms] https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/shared/27.1.0/shared-27.1.0.jar
[ +3 ms] > Could not find common-27.1.0.jar (com.android.tools:common:27.1.0).
[ +1 ms] Searched in the following locations:
[ +1 ms] https://dl.google.com/dl/android/maven2/com/android/tools/common/27.1.0/common-27.1.0.jar
[ ] > Could not find transform-api-2.0.0-deprecated-use-gradle-api.jar (com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api).
[ +59 ms] Searched in the following locations:
[ +2 ms]
https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.jar
[ +5 ms] > Could not find jetifier-processor-1.0.0-beta09.jar (com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta09).
[ ] Searched in the following locations:
[ +4 ms] https://dl.google.com/dl/android/maven2/com/android/tools/build/jetifier/jetifier-processor/1.0.0-beta09/jetifier-processor-1.0.0-beta09.jar
[ ] > Could not find jetifier-core-1.0.0-beta09.jar (com.android.tools.build.jetifier:jetifier-core:1.0.0-beta09).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/jetifier/jetifier-core/1.0.0-beta09/jetifier-core-1.0.0-beta09.jar
[ ] > Could not find protos-27.1.0.jar (com.android.tools.analytics-library:protos:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/27.1.0/protos-27.1.0.jar
[ ] > Could not find core-proto-0.0.2-dev.jar (com.google.test.platform:core-proto:0.0.2-dev).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/google/test/platform/core-proto/0.0.2-dev/core-proto-0.0.2-dev.jar
[ ] > Could not find apkzlib-4.1.0.jar (com.android.tools.build:apkzlib:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/apkzlib/4.1.0/apkzlib-4.1.0.jar
[ ] > Could not find apksig-4.1.0.jar (com.android.tools.build:apksig:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/4.1.0/apksig-4.1.0.jar
[ ] > Could not find annotations-27.1.0.jar (com.android.tools:annotations:27.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/com/android/tools/annotations/27.1.0/annotations-27.1.0.jar
[ ] > Could not find databinding-common-4.1.0.jar (androidx.databinding:databinding-common:4.1.0).
[ ] Searched in the following locations:
[ ] https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-common/4.1.0/databinding-common-4.1.0.jar
[ ] > Could not find baseLibrary-4.1.0.jar (com.android.databinding:baseLibrary:4.1.0).
[ ] Searched in the following locations:
[ +14 ms] https://dl.google.com/dl/android/maven2/com/android/databinding/baseLibrary/4.1.0/baseLibrary-4.1.0.jar
[ +15 ms] * 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 2m 15s
[+1017 ms] Running Gradle task 'assembleDebug'... (completed in 137.9s)
[ +9 ms] Exception: Gradle task assembleDebug failed with exit code 1
对不起,我只是一个非常初学者但我尝试降级gradle,重新安装android studio和vscode和sdk但仍然没有运气。
这是我的 build.gradle:
buildscript
ext.kotlin_version = '1.3.50'
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
allprojects
repositories
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
请注意,我没有安装任何模拟器,但我安装了 android studio 来安装 sdk。它下载了: enter image description here
enter image description here
这里是 grdale.properties:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
这是代理设置的截图: HTTP proxy
这是我运行 gradle build --warning-mode=all
时的屏幕截图:
它给了我没有依赖
enter image description here
包装器.属性:
#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-6.7-all.zip
尝试解决方案后 发生了一个新错误:
Building with sound null safety
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\hh\StudioProjects\untitled1\android\app\build.gradle' line: 26
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
> Could not find transform-api-2.0.0-deprecated-use-gradle-api.jar (com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-ap
i.jar
* 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 49s
Running Gradle task 'assembleRelease'... 52.0s
Gradle task assembleRelease failed with exit code 1
【问题讨论】:
【参考方案1】:由于某种原因,它无法从存储库中获取 .jar 文件。 让我们检查对资源的访问,尝试其中一个链接,例如:https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar 如果已开始下载,则资源可用。
试试这个:
1.在studio中打开设置,找到这个: Repository settings。 您应该在这里拥有所有网址
2.编辑gradle文件:
buildscript
ext.kotlin_version = '1.3.50'
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
allprojects
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
3.在flutter.gradle中也添加这些仓库:
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
4.关闭Android Studio
5.删除C:\UsersYour User中的文件夹.gradle
6.打开Android Studio并再次构建
【讨论】:
感谢您的回答,我编辑了问题并添加了gradle代码。 @HasanMhallak 我编辑了答案,查看存储库设置 还是同样的错误。如果网址正常,我不能下载它需要的所有内容并离线工作吗?对不起,我还是新手,甚至还没有编写任何代码。我只是按照课程中的说明下载了所有内容,并尝试运行 Flutter 附带的 Demo 应用程序。 android studio是2020.3.1.22 win7 x64和flutter 2.2.3 stable。 @HasanMHallak 你可以下载这个文件,但是需要很长时间,因为你需要包含很多 .jar 文件。最好现在解决这个问题,以后不要再处理了:) 尝试从我对你的 gradle 文件的回答中添加 maven 行【参考方案2】:解决方案:
按照@leonid 的建议将build.gardle
更改为:
buildscript
ext.kotlin_version = '1.3.50'
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
allprojects
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
rootProject.buildDir = '../build'
subprojects
project.buildDir = "$rootProject.buildDir/$project.name"
project.evaluationDependsOn(':app')
task clean(type: Delete)
delete rootProject.buildDir
转到android文件夹中的gradle.properties
并添加此行android.enableR8=true
所以它看起来像这样:
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
然后转到C:\src\flutter\packages\flutter_tools\gradle
并查找名为flutter.gradle
的文件并使用您喜欢的任何编辑器对其进行编辑,并将此代码添加到repositories
下:
repositories
mavenCentral()
maven url 'https://jitpack.io'
maven url 'https://dl.google.com/dl/android/maven2'
google()
jcenter()
这应该可以解决问题。
【讨论】:
以上是关于使用 USB 电缆调试时 Gradle 任务 assembleDebug 失败的主要内容,如果未能解决你的问题,请参考以下文章
是否可以在不使用 android studio 中的任何 USB 电缆的情况下通过 wifi 进行调试? [复制]
循环使用 USB 电缆时,Android ADB-over-WiFi 仍会断开连接(?!?)
如何使用连接 USB 电缆调试在 Xcode 未启动的移动设备中执行的 iOS 应用程序