FadedCoder
FadedCoder

Reputation: 1517

Compile multiple modules in Android Gradle Dependency

I'm trying to create an app with andEngine WITH its physicsBox2D extension. For that, I have to add 2 modules and then compile in my app - andEngine and andEngine PhysicsBox2D. I have the following Gradle code -

apply plugin: 'com.android.model.application'

model {

android {
    compileSdkVersion = 22
    buildToolsVersion = "22.0.1"

    defaultConfig.with {
        applicationId = "com.sample.practice"
        minSdkVersion.apiLevel = 9
        targetSdkVersion.apiLevel = 22
        versionCode = 1
        versionName = "1.0"
    }
}

android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles += file('proguard-rules.pro')
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':andEnginePhysicsBox2D')
    compile project(':andEngine')
}

But this code gives this error while running - ...java.exe finished with non zero exit value 2

If I remove compile project(':andEnginePhysicsBox2D') from Gradle, the app runs fine. But this code is important for the app to work. Any ideas how I can implement both andEngine and andEngine PhysicsBox2D in the dependencies of Gradle?

Thanx

PS - I'm using experimental Android Gradle Plugin V.0.2 with Android Studio 1.3 for some NDK stuff.

Upvotes: 5

Views: 1890

Answers (3)

iCREAM
iCREAM

Reputation: 26

I'm using Android Studio 1.2.2 The following script is working fine with me.

See if this can help?

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId 'com.xxxx.yyy'
        minSdkVersion 8
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/gfx/'] } }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile project(':andengine')
    compile project(':andenginebox2dextension')
}

Upvotes: 0

frogatto
frogatto

Reputation: 29285

Box2d extension needs AndEngine module as its dependency and your project also needs both of them as its dependencies. Also It should be noted that order of dependencies matters as well.

So you should make sure you have three gradle files configured like below.

  • Your game gradle file:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile project(':andEngine')
        compile project(':andEnginePhysicsBox2D')
    }
    
  • AndEngine gradle file:

    It does not have any dependency.

  • Box2d Extension gradle file:

    dependencies {
        compile project(':andEngine')
    }
    

Upvotes: 2

FadedCoder
FadedCoder

Reputation: 1517

Solved the problem by this -

1) There were some problems in andEngine, solved those errors.

2) Enabled multiDex in Gradle.

Upvotes: 0

Related Questions