Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add AndEngine to Android Studio

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

like image 965
user1406716 Avatar asked Jan 12 '14 19:01

user1406716


2 Answers

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.

like image 186
gipi Avatar answered Oct 02 '22 07:10

gipi


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.

  1. Download Andengine from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngine
  2. After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter
  3. Create new project in Android Studio
  4. Create new module:
  5. Select File -> New Module -> Android Library
  6. Set Application name to AndEngine
  7. Set Module Name to AndEngine
  8. Set Package Name to org.andengine
  9. Set Minimum SDK 14
  10. Target SDK 19
  11. Compile with 19
  12. Theme None
  13. Keep clicking next until module is created (no difference what you pick)
  14. Enter the folder where you have downloaded Andengine, enter src/org/andengine and copy all the files inside.
  15. Paste the copied files into your new module in your project src/java/org.andengine. After pasting everything remove tha MainActivity that was created on default
  16. Enter the folder where you have downloaded Andengine, copy AndroidManifest and paste it into your new module (src/main)
  17. Add the module to the project:
  18. Select File-> Project Structure -> app-> Dependencies
  19. Click the “+” button and pick “Module Dependency”
  20. Select from the list your AndEngine Module
  21. Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngine')

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:

  1. Download AndengineTMX from github using TortoiseGit: https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
  2. After the dowload use TortoiseGit to switch to branch GLES2-AnchorCenter
  3. Create new project in Android Studio
  4. Create new module:
  5. Select File -> New Module -> Android Library
  6. Set Application name to AndEngineTMXTiledMapExtension
  7. Set Module Name to AndEngineTMXTiledMapExtension
  8. Set Package Name to org.andengine.extension.tmx
  9. Set Minimum SDK 14
  10. Target SDK 19
  11. Compile with 19
  12. Theme None
  13. Keep clicking next until module is created (no difference what you pick)
  14. Enter the folder where you have downloaded AndengineTMX , enter src/org/andengine/extension/tmx and copy all the files inside.
  15. Paste the copied files into your new module in your project src/java/org.andengine.extension.tmx. After pasting everything remove tha MainActivity that was created on default
  16. Enter the folder where you have downloaded AndengineTMX, copy AndroidManifest and paste it into your new module (src/main)
  17. Add the module to the project:
  18. Select File-> Project Structure -> app-> Dependencies
  19. Click the “+” button and pick “Module Dependency”
  20. Select from the list your AndengineTMX Module
  21. Check your project gradle in app folder (build.gradle) and make sure you have a line like this under dependencies - compile project(':AndEngineTMXTiledMapExtension')

You should now be able to use AndEngineTMXTiledMapExtension in your project.

ANDENGINE PHYSICSBOX2D WITH ANDROID STUDIO 0.8.9

  1. Download this file - http://d-h.st/FyC
  2. Unzip the file
  3. You should have 2 jar files, copy them to your project app/libs
  4. Right click on andenginephysicsbox2dextension.jar and select “Add as library” (or something like this)
  5. Open your build.gradle in your app folder
  6. Under dependencies add compile files('lib/physicsbox2d_so_files.jar')

You should now be able to use PhysicsBox2D in your project.

like image 24
Rafael Skubisz Avatar answered Oct 02 '22 07:10

Rafael Skubisz