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

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'

当前回答

我为我的项目找到了这个解决方案 我只是将最低SDK版本设置为21,这就解决了我的问题

android {
    defaultConfig {
        ...
        minSdkVersion 21 //set the minimum sdk version 21
        targetSdkVersion 29
    }
    ...
}

如果您的minSdkVersion为21或更高,则默认启用multidex,并且您不需要multidex支持库。 阅读更多关于multidex https://developer.android.com/studio/build/multidex.html

其他回答

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

志愿者项目/ 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 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

他的问题在这里,移除它

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

why?

注意:不要使用组合play-services目标。它带来了几十个库,使您的应用程序变得臃肿。相反,只指定应用程序使用的特定谷歌Play服务api。

使用你所需要的https://developers.google.com/android/guides/setup

比如位置服务

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

对于云消息传递

com.google.android.gms:play-services-gcm:11.8.0

如果你正在构建DEBUG APK,只需添加:

debug {
            multiDexEnabled true
        }

内部buildTypes

如果你正在构建RELEASE APK,添加 释放块multiDexEnabled为true为-

release {
                ...
                multiDexEnabled true
                ...
        }

我不知道为什么,也许是因为我在Kotlin开发,但要修复这个错误 我最后必须创建一个扩展MultiDexApplication的类,就像这样:

class MyApplication : MultiDexApplication() {
}

然后在manifest。xml中进行设置

<application
        ...
        android:name=".MyApplication">

为了不让任何人感到困惑,我也这样做:

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

对于androidx,这也适用于我:

implementation 'androidx.multidex:multidex:2.0.0'

...

<应用android: name = " android.support.multidex.MultiDexApplication " >

对我没用吗