Search code examples
androidgradleguavamultimap

How to add MultiMaps gradle to android


I want to use MultiMaps in my project because it allows to store duplicate key values. But the problem is with adding gradle. This is how i add:

In my submodule gradle i add:

compile 'com.google.guava:guava:21.0'

Then I get a error saying to add these lines:

If you are using the 'java' gradle plugin in a library submodule add

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

to that submodule's build.gradle file.

So I changed my gradle file like this:

android {
  compileSdkVersion 25
  buildToolsVersion "23.0.2"
  defaultConfig {
    applicationId "com.example.golondon"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
compile 'com.google.guava:guava:21.0'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'
}

But still i get the error. I also tried:

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Then it says to add jack options and to enable jack options I should change my "buildToolsVersion" to 24.0.1.

This gives whole bunch of errors like : Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.BiConsumer


Solution

  • For Android you can't use Guava 21 since it's the first release running only on Java 1.8+. See Guava's README:

    Requires JDK 1.8 or higher. If you need support for JDK 1.6 or Android, use 20.0 for now. In the next release (22.0) we will begin providing a backport for use on Android and lower JDK versions.

    TLDR: Use Guava 20.0.