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 do
Well i had the same problem - This helped me to solve it. http://www.makethegame.net/android-andengine/how-to-setup-andengine-with-android-studio/
I created a tutorial for this - How to add Andengine, Andengine Tile Map, Andengine PhysicsBox2D to Android Studio 0.8.9.
Here is the link, I hope everything works - https://docs.google.com/document/d/1zk2QjNiPvkj52G4qSVivEPrLfkCUVqmnCVH8TfsnER8/edit
ANDENGINE WITH ANDROID STUDIO 0.8.9
Note: I am using the AnchorCenter brach and TortoiseGit to get all the files.
You should now be able to use AndEngine in your project
ANDENGINE TMX TILED MAP EXTENSION WITH ANDROID STUDIO 0.8.9
Note: We do this the same way like with Andengine but we change a few things:
You should now be able to use AndEngineTMXTiledMapExtension in your project.
ANDENGINE PHYSICSBOX2D WITH ANDROID STUDIO 0.8.9
You should now be able to use PhysicsBox2D in your project.
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.
As the question's answers havn't been accepted yet, and I know people are still searching for solutions to this, I found this great website with very very clear and concise instructions to import AndEngine to your Android Studio projects. Here's the link:
http://geq-i.blogspot.com/2014/02/how-to-setup-andengine-in-android-studio.html
All credits go to the user who created this page. I can attest to the fact that this is working perfectly. I JUST used this website after trying 10s of different ways. Only thing to note on the link is the last part:
$ cd <project folder>/AndEngine/src/main
$ rm -r java/org
$ mv org java
This part is copying the org folder from .
to ./main/java
. Best way to do this is to just drag and drop the org folder into main/java when the project has finished building once.
Hope this helps!
Check out this tutorial on how to use andengine in android studio
http://javaprogrammernotes.blogspot.in/2014/05/settings-up-andengine-in-android-studio.html
Brief Summary of the Tutorial(Check out the full tutorial if you face any issue):
Let's assume that you already have created a project and it has default structure. First create folder named third_party in the root directory of the project. Then in third_party directory create subdirectories called andengine and andenginebox2d. I assume that you already downloaded or cloned AndEngine and Box2d extension for it. Put AndEngine and AndEngineBox2d in andengine and andenginebox2d directories respectively. Create file named build.gradle in andengine directory and andenginebox2d directory. Build.gradle files is a file that tells gradle how to build your project.
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-project.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Open settings.gradle that is located in your project's root directory and add two lines to it:
include ':third_party:andengine'
include ':third_party:andenginebox2d'
Next open build.gradle which locates in app directory and add
compile project(':third_party:andengine')
The final step is to open AndroidManifest.xml in andegine and andenginebox2d directories and make them look like this:
<!--?xml version="1.0" encoding="utf-8"?-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.andengine">
<application>
</application>
</manifest>
application block is needed because of bug in manifest merging tool. That's it! Now clean your project and press run. Everything should work just fine.