Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
694 views
in Technique[技术] by (71.8m points)

gradle - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...