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

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'

当前回答

你的方法太多了。 Android dex文件有65536个方法的限制。

对于初学者来说,如果你不需要谷歌播放服务API,只需要位置,请替换

compile 'com.google.android.gms:play-services:11.8.0'

with

compile 'com.google.android.gms:play-services-location:11.8.0'

你可以参考本页的方法来避免它,或者如果需要允许更多: https://developer.android.com/studio/build/multidex.html

其他回答

multiDexEnabled true

请尝试将此添加到您的应用程序defaultConfig{}。这帮我解决了问题

他们给你的答案都不详尽。 问题出在Multidex上。 你必须在应用程序gradle中添加这个库:

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

之后,在应用gradle的defaultConfig中添加:

multiDexEnabled true

您的应用程序必须是Multidex类型.. 你必须把它写在清单上:

android:name=".MyApplication"

“MyApplication”必须是Multidex类,或者必须扩展它。

Goto构建。Gradle的应用程序文件夹, 设置minSdkVersion为21

保存并运行您的应用程序,它应该没有dex错误现在运行

你的方法太多了。 Android dex文件有65536个方法的限制。

对于初学者来说,如果你不需要谷歌播放服务API,只需要位置,请替换

compile 'com.google.android.gms:play-services:11.8.0'

with

compile 'com.google.android.gms:play-services-location:11.8.0'

你可以参考本页的方法来避免它,或者如果需要允许更多: https://developer.android.com/studio/build/multidex.html

你可以跟着这个走。

Android 5.0 (API级别21)之前的平台版本使用Dalvik运行时执行应用程序代码。默认情况下,Dalvik限制每个APK只能使用一个classes.dex字节码文件。为了绕过这个限制,你可以在你的项目中添加multidex支持库:

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

如果你的minSdkVersion设置为21或更高,你所需要做的就是在你的模块级构建中将multiDexEnabled设置为true。Gradle文件,如下所示:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}