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

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 {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.dev.khamsat"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

其他回答

只需要做以下几点:

build.gradle

(module:app)


android {
            ....
      defaultConfig {
              multiDexEnabled true // enable mun
      }
}

并在构建中添加以下依赖项。Gradle应用程序级别文件

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

这将为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
}

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

使用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文件以查看内容。这将为您提供如下所示的方法和引用计数。

dex文件是什么:Android应用程序(APK)文件包含Dalvik可执行(dex)文件形式的可执行字节码文件,其中包含用于运行应用程序的编译代码。

出现这种异常的原因:DEX规范限制了在单个DEX文件中可以引用的方法总数为65,536 (64K引用限制)——包括Android框架方法、库方法和你自己代码中的方法。

步骤1。添加如下依赖项

对于非androidx用户,

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    multiDexEnabled true  //ADD THIS LINE
}

对于android用户,

dependencies {
  implementation 'androidx.multidex:multidex:2.0.1'
}
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true  //ADD THIS LINE
    }

步骤2:

在添加这些同步项目之后,在运行项目之前,请确保在运行之前构建一个项目。否则,您将得到一个异常。

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
    }