Android Studio and AndEngine Setup

My efforts at setting up AndEngine with Android Studio. Hope it benefits somebody. Without much ado here it is:-

Steps

1. Clone AndEngine and AndEnginePhysicsBox2DExtension

C:\ProjectDir>git clone https://github.com/nicolasgramlich/AndEngine.git andEngine
C:\ProjectDir>git clone https://github.com/nicolasgramlich/AndEnginePhysicsBox2DExtension.git andEnginePhysicsBox2DExtension

2. Checkout AnchorCenter Branch

C:\ProjectDir\andEngine>git checkout -b GLES2-AnchorCenter origin/GLES2-AnchorCenter
C:\ProjectDir\andEnginePhysicsBox2DExtension>git checkout -b GLES2-AnchorCenter origin/GLES2-AnchorCenter

  • Now you have github link and anytime you need to update the AndEngine repositories just do git pull.
  • The ET is the project module. andEngine and andEnginePhysicsBox2DExtension are the two library modules.
  • The build.gradle in the two library modules is customized to cater for the default Eclipse sourcesets structure received from the github repository.

3. build.gradle[andEngine]

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.andengine"
        minSdkVersion 15
        targetSdkVersion 19

        ndk {
            moduleName "andengine_shared"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jni.srcDirs = [] // This needs to be done so that gradle does not know about your jni. There are errors otherwise
            jniLibs.srcDirs = ['libs']
        }
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

4. build.gradle [andEnginePhysicsBox2DExtension]

apply plugin: 'com.android.library'
android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.andengine.extension.physics.box2d"
        minSdkVersion 15
        targetSdkVersion 19

        ndk {
            moduleName "andenginephysicsbox2dextension"
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jni.srcDirs = []
            jniLibs.srcDirs = ['libs']
        }
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}
dependencies {
    compile project(':andEngine')
}

5. build.gradle [ET Module]

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "com.cls.etxxxxx"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':andEngine')
    compile project(':andEnginePhysicsBox2DExtension')
}

6. settings.gradle [Project]

include ':ET', ':andEngine', ':andEnginePhysicsBox2DExtension'

7. ndk-build

Now to compile the jni part. Add this line to Application.mk located inside jni folders of both the andEngine library modules.

APP_PLATFORM:=android-19

Now give the command inside the jni folders:-

C:....../jni>ndk-build

This will compile the .so and put them in the libs folders of the modules

8. gradle sync and build

Thats all. Hopefully it should build for you :-).

Edits

Added github integration

Author: admin

Indie Android dev

Leave a Reply

Your email address will not be published. Required fields are marked *