Простая программа получает «Не удается поместить запрошенные классы в один файл dex» при добавлении зависимости Firestore - PullRequest
0 голосов
/ 22 октября 2019

У меня очень простая программа, которая работает нормально - пока я не добавлю зависимости библиотеки для соединения с Firestore. В частности, когда я добавляю реализацию 'com.google.firebase: firebase-firestore: 21.2.0' в мое приложение. (Переход на более раннюю версию 17.xx не имеет значения). Ошибка «Невозможно разместить запрошенные классы в одном файле dex», что для меня не имеет смысла, так как программа настолько проста: ни в коем случае у меня не может быть запущено более 64K методов.

Вот MainActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void addUnitType(View view) {
    return;
}

}

... здесь - activity_main.XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/edit_unit_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:layout_marginStart="7dp"
        android:hint="Unit Type (MedSurg, ICU, etc)"
        android:inputType="text"
        android:textSize="10sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

... это проектный грейд

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

. ..this это приложение gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.nofirestore"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    **implementation 'com.google.firebase:firebase-firestore:21.2.0'**
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
}

И снова, это код, который нарушает работу в приложении gradle - удалите его, и я в порядке, поместите его в зависимости и сбои компиляции:

implementation 'com.google.firebase:firebase-firestore:21.2.0'

а это ошибка

"Cannot fit requested classes in a single dex file"

Есть мысли о том, что дает? Я запустил гораздо более сложные приложения без мультидекса. Я хотел бы знать. Спасибо.

Ответы [ 2 ]

0 голосов
/ 22 октября 2019

Ну, это НЕ было пропущенным

apply plugin: 'com.google.gms.google-services'

Вместо этого это было что-то столь же простое, как minSdkVersion19 : изменение этого значения на 22 избавило от ошибки мультидексальной компиляции, и этоработает отлично!

0 голосов
/ 22 октября 2019

Внутри блока defaultConfig добавьте следующее:

multiDexEnabled true

Также в build.gradle добавьте следующую зависимость:

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

Более подробную информацию о multidex можно найти вСледующая ссылка:

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

...