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

时间:2019-03-13 09:21:45

标签: android gradle flutter

自从我开始将项目升级到AndroidX以来,我一直坚持解决抖动依赖问题。因此,我只创建了一个新项目(0个自定义dart文件),并开始添加主项目的程序包,直到解决依赖项为止。因此,问题仅与android上的构建设置有关,而在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

正在寻找错误的网址。如果我从网址中删除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
}

app / 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

我的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

我已经尝试过构建脚本存储库的许多变体。

我已经尝试使用Android Studio>重构到androidX。我没有更多的旧用法来重构

1 个答案:

答案 0 :(得分:0)

我发现了主要问题。有时,我试图手动清理缓存,以确保以后不会出现缓存问题,而我先使用rm -Rf /Users/felipe/flutter/.pub-cache && flutter clean,然后使用flutter get packages。但是,当您删除.pub-cache文件夹时,下载软件包时它不会自动修复。所以刷新flutter的安装使我可以分别调试每个软件包。

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

这是我当前的文件:

build.grade

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
}

app / 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,因为我看到他可以编译该项目,这有助于我解决问题:)