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

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构建文件中添加依赖项:

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

or

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

or

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

然后在“defaultConfig”部分,添加:

multiDexEnabled true

在targetSdkVersion

minSdkVersion 17
targetSdkVersion 27
multiDexEnabled true

如果你遇到这个错误

错误:Failed to resolve: multidex-instrumentation Open File

您需要将gradle更改为3.0.1

classpath 'com.android.tools.build:gradle:3.0.1'

并将以下代码放入gradle-wrapper.properties文件中

- 4.1 - all.zip distributionUrl = https://services.gradle.org/distributions/gradle

最后

在项目中添加类application并将其引入到AndroidManifest中 哪个是从MultiDexApplication扩展过来的

public class App extends MultiDexApplication {

    @Override
    public void onCreate( ) {
        super.onCreate( );
    }
}

首先运行项目以创建错误,然后清除项目

最后,重新启动项目并享受它

其他回答

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

在Gradle构建文件中添加依赖项:

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

or

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

or

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

然后在“defaultConfig”部分,添加:

multiDexEnabled true

在targetSdkVersion

minSdkVersion 17
targetSdkVersion 27
multiDexEnabled true

如果你遇到这个错误

错误:Failed to resolve: multidex-instrumentation Open File

您需要将gradle更改为3.0.1

classpath 'com.android.tools.build:gradle:3.0.1'

并将以下代码放入gradle-wrapper.properties文件中

- 4.1 - all.zip distributionUrl = https://services.gradle.org/distributions/gradle

最后

在项目中添加类application并将其引入到AndroidManifest中 哪个是从MultiDexApplication扩展过来的

public class App extends MultiDexApplication {

    @Override
    public void onCreate( ) {
        super.onCreate( );
    }
}

首先运行项目以创建错误,然后清除项目

最后,重新启动项目并享受它

当你使用依赖时,你的方法增加了! 谷歌有一个解。叫做Multidex!

注意:确保最小SDK大于14。

在你的构建中。gradle:

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



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

对于androidX使用:

 def multidex_version = "2.0.1"
 implementation 'androidx.multidex:multidex:$multidex_version'

欲了解更多信息,请访问原文链接:

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

你的方法太多了。 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

我用这种方法解决了我同样的问题,你需要遵循2个简单的步骤。我是AndroidX用户,所以对我来说,首先我在构建中实现了这个依赖。Gradle文件在我的项目中的依赖项部分。

实现“androidx.multidex: multidex: 2.0.1”

dependencies {
//for multidex
implementation 'androidx.multidex:multidex:2.0.1'

}

在构建中添加此依赖项后。Gradle文件,然后再次同步您的项目

现在添加到“defaultConfig”部分:

multiDexEnabled真实

defaultConfig {
    applicationId "com.papel.helper"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    multiDexEnabled true
  
}

现在重新构建你的项目并运行:)