我想添加融合的位置服务,但它告诉我一些错误。 帮助我。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "27.0.1"
    defaultConfig {
        applicationId "com.example.adil.bloodbankapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:11.8.0'
    compile 'com.google.firebase:firebase-database:11.8.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'junit:junit:4.12'
    compile 'com.android.support:design:26.1.0'
    compile 'com.github.joielechong:countrycodepicker:2.1.5'
    compile 'com.jaredrummler:material-spinner:1.2.4'
    compile 'hanks.xyz:htextview-library:0.1.5'
    compile 'com.firebaseui:firebase-ui-database:1.2.0'
    compile 'com.google.android.gms:play-services:11.8.0'
}


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

当前回答

该错误是由你的应用程序Gradle文件中类依赖的数量引起的。如果类超过72,400个,您可能希望使用multidex作为更好地处理文件索引的解决方案。更多信息请访问:https://developer.android.com/studio/build/multidex

其他回答

在构建应用程序

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.proyecto.marketdillo"
    minSdkVersion 14
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'

修改应用程序或模块的build.gradle

android {
    defaultConfig {
        ...
        minSdkVersion 21 <----- *here
        targetSdkVersion 26
        multiDexEnabled true <------ *here
    }
    ...
}

根据官方文件

Multidex support for Android 5.0 and higher Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher, you do not need the multidex support library. For more information on the Android 5.0 runtime, read ART and Dalvik.

https://developer.android.com/studio/build/multidex

使用multidex支持应该是最后的手段。默认情况下,gradle构建会为你的APK收集大量的可传递依赖项。正如谷歌开发者文档中建议的那样,首先尝试从项目中删除不必要的依赖项。

使用命令行导航到Android项目根目录。 您可以获得如下所示的编译依赖项树。

gradlew app:dependencies --configuration debugCompileClasspath

你可以得到完整的依赖树列表

gradlew app:dependencies

然后从应用build.gradle中删除不必要的或可传递的依赖项。作为一个例子,如果你的应用程序使用名为“com.google的依赖。你可以排除你不需要的库/模块。

implementation ('com.google.api-client:google-api-client-android:1.28.0'){
   exclude group: 'org.apache.httpcomponents'
   exclude group: 'com.google.guava'
   exclude group: 'com.fasterxml.jackson.core'
   }

然后在Android Studio中选择Build > Analyze APK… 选择发布/调试APK文件以查看内容。这将为您提供如下所示的方法和引用计数。

我在颤振项目中使用了以下解决方案:

志愿者项目/ app /构建开放。Gradle并添加以下行:

android {
    ...

    defaultConfig {
        ...
        
        minSdkVersion 21
        multiDexEnabled true
    }
}

then

dependencies {
    ...

    implementation 'com.android.support:multidex:1.0.3'
}

如果你已经迁移到AndroidX,你会想要这样:

dependencies {
    ...

    implementation 'androidx.multidex:multidex:2.0.1'
}

这个解决方案对我很有效。谢谢你的提问。

在痛苦了两个小时后找到了解决办法。

文件路径:android/build.gradle

为我工作

defaultConfig {
    applicationId "com.something"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true --> This works for me
}

如果您的minSdkVersion设置为21或更高,则multidex默认启用,您不需要multidex支持库。-参考:https://developer.android.com/studio/build/multidex#mdex-gradle