我试图按照谷歌的指南,但它说要创建一个新的空模块,在最新版本中没有选项......我该怎么做?谢谢你。
1 回答
这是整个教程如何使用 Android Studio 和 Gradle 使用 AndEngine 和 PhysicsBox2D 扩展。只要 gradle 不支持本机库,我就使用此处描述的 hack Android Studio Gradle with native libs error
我的项目结构是:
- ProjectRoot
- build.gradle
- settings.gradle
- MainProject
-- src
-- res
--aidl
- Modules
-- AndEngine
--- src
--- res
--- libs
---- libs.jar
--- build.gradle
-- PhysicBox2D
--- src
--- res
--- libs
---- 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']
}
}
}
一切正常。我希望我已经提供了所有必要的信息以使其运行。