3

I'm trying to enable MultiDex. I added multiDexEnabled true and compile 'com.android.support:multidex:1.0.3' to build.gradle. I made a java file

public class ApplicationClass extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);  // <----------
    }
}

and added android:name=".ApplicationClass" to manifest file.

But in the java file, in MultiDex.install(this); the MultiDex part is red and it says Cannot resolve symbol 'MultiDex'. And gradle sync fails. I also tried adding android:name="android.support.multidex.MultiDexApplication" to manifest, instead of creating the java file and extending application class. It didn't work either. The part MultiDexApplication is red and it says unresolved class 'MultiDexApplication'

I think there is something wrong with the android support library in my system. Multidex is from this library. Also when I change any of 'com.android.support:appcompat-v7:26.+' (to the specific version 26.0.1 as suggested by Android Studio) or 'com.android.support.constraint:constraint-layout:1.0.2' (to the newer version 1.1.2), gradle sync fails.

I looked into <SDK>/extras directory. And I see there are three different support directories. Not sure if this has something to do with the problem.

enter image description here

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.vvaezian.multilingovocabularypractice"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true    <--- added ---
    }
    buildTypes {
        debug {
            buildConfigField 'String', "ApiKey", MultiLingo_ApiKey
        }
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField 'String', "ApiKey", MultiLingo_ApiKey
        }
    }

    packagingOptions {
        exclude 'project.properties'
        exclude 'META-INF/INDEX.LIST'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    testImplementation 'junit:junit:4.12'

    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'

    implementation('com.google.cloud:google-cloud-translate:1.3.1') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'org.json', module: 'json'
    }
    annotationProcessor 'com.google.cloud:google-cloud-translate:1.3.1'
    compile 'com.android.support:multidex:1.0.3'  // <----- added ----
    // using 'implementation' instead of 'compile' didn't resolve the issue
}

Also the log file does not say why the gradle sync fails. There is only one line that says Too many events posted ...

2018-08-01 13:56:54,922 [e-1024-b01]   INFO - e.project.sync.GradleSyncState - Started sync with Gradle for project 'MultiLingoVocabularyPractice'. 
2018-08-01 13:56:54,924 [e-1024-b01]   INFO - idea.project.IndexingSuspender - Consuming IndexingSuspender activation event: SYNC_STARTED 
2018-08-01 13:56:54,924 [e-1024-b01]   INFO - idea.project.IndexingSuspender - Starting batch update for project: Project '/local-scratch/vvaezian/AndroidStudioProjects/MultiLingoVocabularyPractice' MultiLingoVocabularyPractice 
2018-08-01 13:56:54,934 [hread 1914]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /local-scratch/vvaezian/android-studio/jre 
2018-08-01 13:56:54,935 [hread 1914]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /local-scratch/vvaezian/android-studio/jre 
2018-08-01 13:56:54,943 [hread 1914]   INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: -Didea.version=3.1 -Djava.awt.headless=true -Pandroid.injected.build.model.only=true -Pandroid.injected.build.model.only.advanced=true -Pandroid.injected.invoked.from.ide=true -Pandroid.injected.build.model.only.versioned=3 -Pandroid.injected.studio.version=3.1.3.0 -Pandroid.builder.sdkDownload=false --init-script /tmp/ijinit.gradle 
2018-08-01 13:56:57,640 [hread 1916]   INFO - agnostic.FrequentEventDetector - Too many events posted, #7. Event: java.awt.event.InvocationEvent[INVOCATION_DEFAULT,runnable=LaterInvocator.FlushQueue,notifier=null,catchExceptions=false,when=1533157017640] on sun.awt.X11.XToolkit@5b185819 
2018-08-01 13:56:57,676 [hread 1914]   INFO - e.project.sync.GradleSyncState - Started setup of project 'MultiLingoVocabularyPractice'. 
2018-08-01 13:56:57,677 [e-1024-b01]   INFO - idea.project.IndexingSuspender - Consuming IndexingSuspender activation event: SETUP_STARTED 
2018-08-01 13:56:57,789 [hread 1916]   INFO - idea.project.IndexingSuspender - Indexing suspended (context: Project Setup) 
2018-08-01 13:56:57,995 [e-1024-b01]   INFO - ule.android.SdkModuleSetupStep - Set Android SDK 'Android API 26 Platform (1)' (/local-scratch/vvaezian/SDK) to module 'app' 
2018-08-01 13:56:58,005 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/build-tools/26.0.1/package.xml 
2018-08-01 13:56:58,009 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/build-tools/27.0.3/package.xml 
2018-08-01 13:56:58,012 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/emulator/package.xml 
2018-08-01 13:56:58,016 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/extras/android/m2repository/package.xml 
2018-08-01 13:56:58,020 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/extras/google/m2repository/package.xml 
2018-08-01 13:56:58,024 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/extras/m2repository/com/android/support/constraint/constraint-layout-solver/1.0.2/package.xml 
2018-08-01 13:56:58,028 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/extras/m2repository/com/android/support/constraint/constraint-layout/1.0.2/package.xml 
2018-08-01 13:56:58,032 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/patcher/v4/package.xml 
2018-08-01 13:56:58,035 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/platform-tools/package.xml 
2018-08-01 13:56:58,039 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/platforms/android-23/package.xml 
2018-08-01 13:56:58,042 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/platforms/android-24/package.xml 
2018-08-01 13:56:58,045 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/platforms/android-25/package.xml 
2018-08-01 13:56:58,049 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/platforms/android-26/package.xml 
2018-08-01 13:56:58,053 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/sources/android-26/package.xml 
2018-08-01 13:56:58,056 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/system-images/android-24/google_apis_playstore/x86/package.xml 
2018-08-01 13:56:58,060 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/system-images/android-26/google_apis/x86/package.xml 
2018-08-01 13:56:58,063 [hread 1917]   INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/tools/package.xml 
2018-08-01 13:56:58,118 [hread 1914]   INFO - e.project.sync.GradleSyncState - Gradle sync failed (3s 196ms) 
2018-08-01 13:56:58,120 [e-1024-b01]   INFO - idea.project.IndexingSuspender - Consuming IndexingSuspender deactivation event: SYNC_FINISHED 
2018-08-01 13:56:58,120 [e-1024-b01]   INFO - idea.project.IndexingSuspender - Finishing batch update for project: Project '/local-scratch/vvaezian/AndroidStudioProjects/MultiLingoVocabularyPractice' MultiLingoVocabularyPractice 
2018-08-01 13:56:58,150 [e-1024-b01]   INFO - pl.ProjectRootManagerComponent - project roots have changed 
2018-08-01 13:56:58,169 [hread 1916]   INFO - idea.project.IndexingSuspender - Indexing released (context: Project Setup) 
2018-08-01 13:56:58,199 [hread 1916]   INFO - .diagnostic.PerformanceWatcher - Pushing properties took 2ms; general responsiveness: ok; EDT responsiveness: ok 
2018-08-01 13:56:58,254 [hread 1916]   INFO - .diagnostic.PerformanceWatcher - Indexable file iteration took 55ms; general responsiveness: ok; EDT responsiveness: ok 
2018-08-01 13:56:58,303 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Clearing symbols finished in 0 s. 
2018-08-01 13:56:58,304 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Building symbols in FAST mode, 0 source files from total 0 project files 
2018-08-01 13:56:58,305 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Loading Module Maps finished in 0 s. 
2018-08-01 13:56:58,305 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Saving Module Maps finished in 0 s. 
2018-08-01 13:56:58,305 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Saving Module Maps finished in 0 s. 
2018-08-01 13:56:58,305 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Loaded 0 tables for 0 files (0 project files) 
2018-08-01 13:56:58,305 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Building symbols for 0 source files 
2018-08-01 13:56:58,306 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Building symbols for 0 unused headers 
2018-08-01 13:56:58,307 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Building symbols finished in 0 s. 
2018-08-01 13:56:58,307 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Saving modified symbols for 0 files (0 tables of total 0) 
2018-08-01 13:56:58,307 [hread 1916]   INFO -       #com.jetbrains.cidr.lang - Saving symbols finished in 0 s. 
LoMaPh
  • 1,476
  • 2
  • 20
  • 33

7 Answers7

2
    MultiDex.install(this); 

removed this lines in Applicationenter code here

1

Multidex problems occurs when there are dependencies in gradle that needs to be updated or you have dependencies with different version number in test compile. So, you needs to make sure first about dependencies updated version numbers. Your problem will be solved, if there will be version number issue.

  • Can you please give more details on what exactly do I need to do. As I noted in the post when I change any of `'com.android.support:appcompat-v7:26.+'` (to the specific version 26.0.1 as suggested by Android Studio) or `'com.android.support.constraint:constraint-layout:1.0.2'` (to the newer version 1.1.2), gradle sync fails. Also I added the log file. – LoMaPh Aug 01 '18 at 21:17
  • 1
    It seems the issue of your sdk path. 'com.android.support:appcompat-v7:26.0.1'. In your logcat, while setting SDK 2018-08-01 13:56:58,005 [hread 1917] INFO - s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/build-tools/26.0.1/package.xml 2018-08-01 13:56:58,009 [hread 1917] INFO s.RepoProgressIndicatorAdapter - Parsing /local-scratch/vvaezian/SDK/build-tools/27.0.3/package.xml It sets two different versions of SDK build-tools. This may cause of problem – Zubaria Ashraf Aug 02 '18 at 05:27
1

import android.support.multidex.MultiDex;

1

This pops up at the top when you google "cannot resolve symbol MultiDexApplication". Thus, I add what helped me:

  • If you changed the targetSdkVersion from < 21 to 21+ you see this error

  • Reason: You only need to MyApplication extends MultiDexApplication when targeting API < 21 see documentation.

I.e. to fix it just:

public class MyApplication extends Application
hb0
  • 3,350
  • 3
  • 30
  • 48
1

if you migrated on androidX (which most probably did) make sure to use the correct imports:

import androidx.multidex.MultiDex
import androidx.multidex.MultiDexApplication
imansdn
  • 968
  • 1
  • 7
  • 17
0

Seeing that you are supporting minimal sdk version 15 (Android 4.0.3)

minSdkVersion 15

According to https://developer.android.com/studio/build/multidex, you need to change

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

to

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

Because, the implementation style is for Multidex support after Android 5.0.

shizhen
  • 12,251
  • 9
  • 52
  • 88
-1

In my case the source of the problem was that I had deleted the folder example in the package structure com.example.vvaezian.multilingovocabularypractice but had forgotten to make the change in gradle file

defaultConfig {
    applicationId "com.example.vvaezian.multilingovocabularypractice"
    ...
}

Also I commented out buildToolsVersion "26.0.1".

LoMaPh
  • 1,476
  • 2
  • 20
  • 33