这是完整的教程,说明如何使用Android Studio和Gradle处理AndEngine和PhysicsBox2D扩展.只要gradle不支持本机库,我就使用这里描述的hack Android Studio Gradle with native libs error
我的项目结构是:
?-项目根
?-build.gradle
?-settings.gradle
?-主项目
?-src
?-资源
?-艾德尔
?-模块
?-AndEngine
?-src
?-资源
?-库
?—- libs.jar
?-build.gradle
?-PhysicBox2D
?-src
?-资源
?-库
?—- libs.jar
?-build.gradle
?— settings.gradle
在AndEngine和PhysicsBox2D中,我都将文件夹armeabi,armeabi-v7等放入lib文件夹,然后将其压缩并重命名为libs.jar.我在上面给出的链接中对此进行了描述.
我的主要settings.gradle文件如下所示
include 'Modules:AndEngine'
include 'Modules:PhysicBox2D'
然后像这样build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
}
apply plugin: 'android'
dependencies {
compile project(':Modules:PhysicBox2D')
compile project(':Modules:AndEngine')
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
android {
compileSdkVersion 19
buildToolsVersion "19"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['MainProject/src']
resources.srcDirs = ['MainProject/resources']
aidl.srcDirs = ['MainProject/src']
renderscript.srcDirs = ['MainProject/src']
res.srcDirs = ['MainProject/res']
assets.srcDirs = ['MainProject/assets']
}
instrumentTest.setRoot('MainProject/tests')
}
dependencies {
}
defaultConfig {
...
}
signingConfigs {
...
}
buildTypes {
debug {
...
}
release {
...
}
}
}
模块/PhysicBox2D/settings.gradle
include ':Modules:AndEngineGLES2'
模块/PhysicsBox2D/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
}
apply plugin: 'android-library'
dependencies {
compile project(':Modules:AndEngineGLES2')
compile fileTree(dir: 'libs', include: 'libs.jar')
}
android {
buildToolsVersion "19"
compileSdkVersion 19
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
repositories {
mavenCentral()
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['aidl']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
模块/AndEngine/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
}
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: 'libs.jar')
}
android {
buildToolsVersion "19"
compileSdkVersion 19
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
repositories {
mavenCentral()
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['aidl']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
而且一切正常.我希望我已放入所有必要的信息以使其运行.