Android studio3.4.1中使用flutter和gradle过程中的坑

1、由于是初始玩这个,不熟悉,导致移动了flutter sdk的位置后,怎么都无法运行程序,在setting中修改路径后,dart packages的class位置始终是旧的位置,无法正常运行,最后手动修改最外面的.packages中的文件路径为新的flutter位置后方可正常使用。

2、flutter build apk无法正常编译:
A:要有签名文件,修改key.properties:

storePassword=生成key时的输入的密码
keyPassword=生成key时输入的
keyAlias=生成key时用的别名
storeFile=key文件的位置

开始在最后这个key文件的位置,输入绝对路径后,报错,编译通不过,加了–stacktrace后提示显示路径不对,编译自动找程序文件夹中android下面app文件夹,最后手动复制过去。

B、参考https://blog.csdn.net/qq_30359677/article/details/81387183
在/android/app/build.gradle修改签名部分的相关内容后无法编译,百度N个网页后:

另外增加:找到android{,在这个下面:
lintOptions {
disable ‘InvalidPackage’
//disable ‘MissingTranslation’
checkReleaseBuilds false //去掉这个build会报错
}

修改以上后,用flutter build apk,成功编译

3、剩余问题:
在最外面build.gradle中:
classpath ‘com.android.tools.build:gradle:3.2.1’ //有人这个3.2.1是gradle插件版本号,不是AS版本号,改成3.4.1后无法编译,对应在android\gradle\wrapper\gradle-wrapper.properties中:
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
把gradle-4.10.2-all.zip改成gradle-5.1.1-all.zip或gradle-5.4.1-all.zip也不行,gradle的zip都已经正确下载,也就是说这两个地方任意一个地方修改都无法编译,没找到原因,不知道哪位高手清楚。

以下是错误显示,注意下面的Could not get resource后面的网址我手动点击是可以正常打开的:

Initializing gradle… 1.6s
Resolving dependencies…

  • Error running Gradle:
    ProcessException: Process “E:\Python\AndroidFlutter\flutter_app\android\gradlew.bat” exited abnormally:

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘android’.

Could not resolve all artifacts for configuration ‘:classpath’.
Could not resolve com.android.tools.build:gradle:3.4.1.
Required by:
project :
Could not resolve com.android.tools.build:gradle:3.4.1.
Could not get resource ‘https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom’.
Could not GET ‘https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom’. Received status code 400 from server: Bad Request
Could not resolve com.android.tools.build:gradle:3.4.1.
Could not get resource ‘https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom’.
Could not GET ‘https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom’. Received status code 400 from server: Bad Request

  • 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 2s
Command: E:\XXXXXXX\flutter_app\android\gradlew.bat app:properties

Please review your Gradle project setup in the android/ folder.

你可能感兴趣的:(Android,Studio3.4.1,Flutter学习)