gpt4 book ai didi

android - Flutter - 无法在android设备中运行

转载 作者:行者123 更新时间:2023-12-03 13:30:01 31 4
gpt4 key购买 nike

嗨,我在没有在 android 设备中调试我的项目的情况下运行时收到此错误。

FAILURE: Build failed with an exception.

* 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-c8e3b9485386425213e2973126d6f57e7ed83c54)' to match attributes
{artifactType=android-classes, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for IdentityTransform: C:\Users\Admin\.gradle\caches\modules-2\files-2.1\io.flutter\arm64_v8a_debug\1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54\d84df37647d9c0eb0da1f86ba05744d618192eb7\arm64_v8a_debug-1.0.0-c8e3b9485386425213e2973126d6f57e7ed83c54.jar.
> Cannot parse result path string:

* 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 40s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 42.5s
Exception: Gradle task assembleDebug failed with exit code 1
我在代码中使用了连接插件,当我尝试运行 flutter build apk 时出现错误消息
Note: C:\Users\Admin\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\connectivity-0.4.9\android\src\main\java\io\flutter\plugins\connectivity\ConnectivityBroadcastReceiver.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
有人可以帮我弄这个吗?提前致谢。
更新:我可以在三星 j7 中运行它,但在三星 a7 中出现上述错误
我用来检查连接性的代码
import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
import 'dart:io';
class NetworkConnection{
Future<String> checkInternetConnectivity(BuildContext context) async
{
var result = await Connectivity().checkConnectivity();
String connection = "unknown";
if(result == ConnectivityResult.none)
{
//_showToast(context,"No Connectivity");
connection = "not connected";
}
else if(result == ConnectivityResult.mobile)
{
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
connection = "connected";
}
} on SocketException catch (_) {
connection = "not connected";
}

//_showToast(context,"Connected to mobile");

}
else if(result == ConnectivityResult.wifi)
{
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
connection = "connected";
}
} on SocketException catch (_) {
connection = "not connected";
}
//_showToast(context,"Connected to wifi");

}
return connection;
}
}
我的 flutter 医生 -v 看起来像这样
[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.18362.1016], locale en-IN)
• Flutter version 1.20.2 at C:\src\flutter
• Framework revision bbfbf1770c (7 days ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\Admin\AppData\Local\Android\Sdk
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = C:\Users\Admin\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin version 48.0.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2019.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.4
• Flutter plugin version 45.1.2
• Dart plugin version 193.6911.31

[√] VS Code (version 1.48.0)
• VS Code at C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.13.2

[√] Connected device (1 available)
• SM A750F (mobile) • 32008575eabc85fb • android-arm64 • Android 10 (API 29)
这是我的 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 29

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.sfav1"
minSdkVersion 16
targetSdkVersion 29
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'
}

最佳答案

看来您没有设置权限 InternetAndroidManifest.xml .
看看这个Issue .

关于android - Flutter - 无法在android设备中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63325441/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com