gpt4 book ai didi

android - 构建到 Android 时解决 gradle 依赖关系的问题

转载 作者:IT王子 更新时间:2023-10-29 06:45:27 27 4
gpt4 key购买 nike

自从我开始将项目升级到 AndroidX 以来,我一直致力于解决 Flutter 对 Android 的依赖性问题。所以我只是创建一个新项目(0 个自定义 dart 文件)并开始添加我的主项目的包,直到解决依赖关系。因此,问题仅与 Android 上的build设置有关,而在 iOS 上可以完美运行。

项目编译,直到我添加 firebase_aut 包(支持 androidX 的任何版本):

ERROR: Could not find com.com.myapp.android.tools.build:gradle:3.3.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/com/myapp/android/tools/build/gradle/3.3.1/gradle-3.3.1.pom
- https://dl.google.com/dl/android/maven2/com/com/myapp/android/tools/build/gradle/3.3.1/gradle-3.3.1.jar
- https://jcenter.bintray.com/com/com/myapp/android/tools/build/gradle/3.3.1/gradle-3.3.1.pom
- https://jcenter.bintray.com/com/com/myapp/android/tools/build/gradle/3.3.1/gradle-3.3.1.jar
Required by:
project :firebase_auth

它正在查找错误的 url。如果我从 url 中删除 com/myapp,它可以找到项目所需的文件。

我的构建文件:

build.gradle:

buildscript {
repositories {
maven { url 'https://dl.google.com/dl/android/maven2' }
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}

allprojects {
repositories {
maven { url 'https://dl.google.com/dl/android/maven2' }
jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}

应用程序/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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.myapp.app"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

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 {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha04'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
implementation 'androidx.multidex:multidex:2.0.1'
}

apply plugin: 'com.google.gms.google-services'

我的 src 结构:

android
>app
>src
>debug
>AndroidManifest.xml
>main
>java
>com
>myapp
>app
>MainActivity.java
...

我的 gladle.properties:

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

来 self 的 pubspec 的依赖项:

dependencies:
flutter:
sdk: flutter
flutter_redux: ^0.5.3
meta: ^1.1.6
redux: ^3.0.0
redux_persist_flutter: ^0.8.1
flutter_markdown: ^0.2.0
firebase_auth: ^0.8.1+1
google_sign_in: ^4.0.1+1
flutter_facebook_login: ^1.2.0
cloud_firestore: ^0.9.0+2
flutter_range_slider: 1.1.0
just_debounce_it: ^2.1.0
camera: ^0.4.0+3
image_picker: ^0.5.0+3
exif: ^1.0.1
uuid: ^2.0.0
firebase_storage: ^2.1.0+1
image: ^2.0.7
transparent_image: ^0.1.0
share_extend: ^1.0.4
http: ^0.12.0+1
flutter_native_image:
git: https://github.com/btastic/flutter_native_image.git
intl: ^0.15.7
badges: ^0.0.6
url_launcher: ^5.0.1
geolocator: ^3.0.1
geoflutterfire: #^2.0.0
git: https://github.com/felipecesar42/GeoFlutterFire.git

我已经尝试了 buildscript 存储库的许多变体。

我已经尝试使用 Android Studio > 重构到 android X。我没有更多的旧用法可以重构

最佳答案

我发现了主要问题。有时我试图手动清理缓存以确保我以后不会遇到缓存问题并且我正在使用 rm -Rf/Users/felipe/flutter/.pub-cache && flutter clean 然后 flutter get packages。但是,当您删除 .pub-cache 文件夹时,它不会在下载包时自动修复。所以刷新 flutter 安装允许我单独调试每个包。

我开始了一个新项目并手动添加了每个数据包,试图避免使用 Android Studio > Refactor to Android X 和它提供的自动 gradle 更新。

这里是我的当前文件:

构建等级

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}

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
}

应用程序/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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

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 {
androidTestImplementation 'androidx.test:runner:1.1.2-alpha04'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.multidex:multidex:2.0.1'
}
apply plugin: 'com.google.gms.google-services'

gladle.properties

org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

pubspec.yaml:

dependencies:
flutter:
sdk: flutter
firebase_auth: ^0.8.1+4
flutter_redux: ^0.5.3
meta: ^1.1.6
redux: ^3.0.0
flutter_markdown: ^0.2.0
google_sign_in: ^4.0.1+1
flutter_facebook_login: ^2.0.0
cloud_firestore: ^0.9.5+2
flutter_range_slider: ^1.1.0
just_debounce_it: ^2.1.0
camera: ^0.4.2
image_picker: ^0.5.0+6
firebase_storage: ^2.1.0+1
transparent_image: ^0.1.0
share_extend: ^1.0.4
http: ^0.12.0+1
flutter_native_image:
git: https://github.com/btastic/flutter_native_image.git
intl: ^0.15.7
badges: ^0.0.6
url_launcher: ^5.0.1
geolocator: ^3.0.1
geoflutterfire: ^2.0.3+2
redux_persist_flutter: ^0.8.1

感谢@Xuzan,我看到他可以编译项目,这帮助我解决了问题:)

关于android - 构建到 Android 时解决 gradle 依赖关系的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138222/

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