0

I'm trying to create an android application that depends on java code from a java library module, but whenever I try to use any objects from that java library, I always get the following

Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_121\bin\java.exe'' finished with non-zero exit value 1

I've looked at the following Execution failed for task ':app:transformClassesWithDexForDebug' while implementing Google sign in for Android and I've tried pretty much every suggestion, but it still won't build. My java library does use the json library that android uses, and I get a few warnings about that, but it says it will just be ignored

Here's my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "pwils33.familymap"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries false
        incremental true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile project(':shared')
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:multidex:1.0.1'
}

I'm using the module for another java application that I've built so I can't convert it into an android library. Any help would be appreciated

EDIT I've tried making my application a multi dex application as well, that's not working either, here's my manifest for the application

<?xml version="1.0" encoding="utf-8"?>
<manifest package="pwils33.familymap"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication">
        <activity android:name=".activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>
Community
  • 1
  • 1
pwils33
  • 1
  • 1

3 Answers3

0

Try below code to fix your issues:

android {
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        multiDexEnabled true
    }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}
Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42
Nikhil Sharma
  • 593
  • 7
  • 23
0

Include multidex library in your app's module build.gradle file:

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

Then enable multidexing in defaultConfig section by adding:

multiDexEnabled true 

If you don't override Application, edit manifest's <Application> tag, and add:

<application
        android:name="android.support.multidex.MultiDexApplication">

If you do override Application class, extend it from MultiDexApplication class (from above mentioned multidex library:

public class AndroidApplication extends MultiDexApplication { ... }

If you do override Application class and it actually extend other class (for example because of using ORM library that often require to extend from it's class), install multidex by calling from attachBaseContext:

MultiDex.install(this);

More details are available in Google's documentation.

Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42
0

I finally figured it out. It turns out that multi-dex libraries don't support 1.8, since I have java 8 on my computer, when it found the compiled code from my java module, it was breaking it. I added the following lines to my build.gradle to my java module to finally get it to work

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
...
}
pwils33
  • 1
  • 1