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

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'

当前回答

我知道我的答案晚了,但是,我确信这个问题主要是由一个依赖项引起的,“com.google.android.gms:play-services”。请阅读完整的答案,以便更好地理解问题和解决方案。

在我的情况下,我使用的是'com.google.android.gms:play-services-location:21.0.1',这是它的最新版本,当我写这个答案的时候。它有太多的方法计数。 我使用它的唯一动机是从用户的设备中获取位置。谷歌建议只使用play-services-location来获取位置,所以我不想替换这个依赖来完成我的工作。 经过无数次谷歌搜索,我发现,

您可以降低版本

之前的稳定版本,来完成你的工作。对于我来说,最适合我的版本是17.1.0。所以我建议你只使用这个特定的版本,如果你的用例使用play-services-location完全像我的。

做这些改变

implementation 'com.google.android.gms:play-services-location:21.0.1'

to

implementation 'com.google.android.gms:play-services-location:17.1.0'

尽管如此,在你的代码中总是有启用多索引的选项,但是,在我看来,这是解决这个问题最低效的方法。

如果你能找到导致dex文件大小变大的根本原因 method count,那么我想你应该调整或替换它 依赖。

其他回答

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.dev.khamsat"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

我遇到过这个错误两次,解决方案是;检查你的应用程序gradle文件来查看你的目标SDk,如果它是20或更高,只需添加一行到你的defaultconfig {multiDexEnabled true}

否则,如果targetSDK小于20,则将该行添加到defaultConfig中,并添加一个依赖项

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

点击这个链接了解更多。

https://developer.android.com/studio/build/multidex#mdex-gradle

这将为Kotlin或Java项目完成工作。

步骤1 -在Gradle Scripts下找到build.gradle(Module:app)

步骤2 -添加multiDexEnabled true如下所示:

    compileSdkVersion 29

    defaultConfig {
        applicationId "com.example.appname"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true //addded
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

步骤3 -添加multidex依赖项

dependencies {
implementation 'com.android.support:multidex:2.0.0' //added
}

最后,同步你的项目。享受吧!

在构建应用程序

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'

我不知道为什么,也许是因为我在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 " >

对我没用吗