Unable to add AndEngine to Android Studio

user1406716 picture user1406716 · Jan 12, 2014 · Viewed 10.5k times · Source

I am trying to almost 2 days to add AndEngine to Android Studio but unable to do so. I tried the following two methods, neither worked.

1st Try I download the AndEngine code from GitHub Link -- this is NOT a Gradle Project

and tried to add it to my Android Studio build.gradle and settings.gradle, but i get this error, my screenshot: https://postimg.cc/image/5mcvpvsar/ (I think I am getting this error because AndEngine is not a gradle project - HOW TO MAKE IT A GRADLE PROJECT??)

2nd Try I have also tried adding the andengine.jar (file I just googled for) in /libs folder and do right-click --> "Add as Library" but still I cannot do "import org.andengine...." in my project files.

All tutorials available online are in Eclipse, I am using Android Studio.

I am not even able to start.

UPDATE: Yes, I gave up using Android Studio for AndEngine! Took me 15mins to do this in Eclipse, compared to the unsuccessful weekend (which i will never get back!) I spent on Android Studio

Answer

gipi picture gipi · Jan 12, 2014

I use this techique: I set this in my settings.gradle

include 'andengine'

project(':andengine').projectDir = new File(settingsDir, '../relative/path/to/andengine')

that is in the root directory of the project (I think gradle has already created it for your main project).

In AndEngine use a build.gradle like the following for the AndEngine project

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

and add in the dependencies of your project

compile project(':andengine')

Maybe you have to close and reopen Android Studio, but normally for me this works.

BTW after have write the answer I see that someone has opened a pull request for a gradle build file.