android - Android - 将LibGDX项目放入Anroid App项目

我正在使用Android Studio ,我该如何将LibGDX项目放入Android App项目中(不是将Android App项目放入LibGDX项目中)?

这是将libGDX模块导入Android App项目时遇到的问题。


Could not find method android() for arguments [build_f3607d3g9oo7ee40quzhms085$_run_closure1@18e45678] on project ':android' of type org.gradle.api.Project.



应该做哪些额外的配置?

这是我的Android Build Gradle文件。


android {


 buildToolsVersion"29.0.2"


 compileSdkVersion 29


 sourceSets {


 main {


 manifest.srcFile 'AndroidManifest.xml'


 java.srcDirs = ['src']


 aidl.srcDirs = ['src']


 renderscript.srcDirs = ['src']


 res.srcDirs = ['res']


 assets.srcDirs = ['assets']


 jniLibs.srcDirs = ['libs']


 }



 }


 packagingOptions {


 exclude 'META-INF/robovm/ios/robovm.xml'


 }


 defaultConfig {


 applicationId"com.motivado.game"


 minSdkVersion 14


 targetSdkVersion 29


 versionCode 1


 versionName"1.0"


 }


 buildTypes {


 release {


 minifyEnabled false


 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'


 }


 }


}



// called every time gradle gets executed, takes the native dependencies of


// the natives configuration, and extracts them to the proper libs/ folders


// so they get packed with the APK.


task copyAndroidNatives {


 doFirst {


 file("libs/armeabi/").mkdirs()


 file("libs/armeabi-v7a/").mkdirs()


 file("libs/arm64-v8a/").mkdirs()


 file("libs/x86_64/").mkdirs()


 file("libs/x86/").mkdirs()



 configurations.natives.files.each { jar ->


 def outputDir = null


 if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")


 if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")


 if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")


 if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")


 if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")


 if(outputDir != null) {


 copy {


 from zipTree(jar)


 into outputDir


 include"*.so"


 }


 }


 }


 }


}



tasks.whenTaskAdded { packageTask ->


 if (packageTask.name.contains("package")) {


 packageTask.dependsOn 'copyAndroidNatives'


 }


}



task run(type: Exec) {


 def path


 def localProperties = project.file("../local.properties")


 if (localProperties.exists()) {


 Properties properties = new Properties()


 localProperties.withInputStream { instr ->


 properties.load(instr)


 }


 def sdkDir = properties.getProperty('sdk.dir')


 if (sdkDir) {


 path = sdkDir


 } else {


 path ="$System.env.ANDROID_HOME"


 }


 } else {


 path ="$System.env.ANDROID_HOME"


 }



 def adb = path +"/platform-tools/adb"


 commandLine"$adb", 'shell', 'am', 'start', '-n', 'com.motivado.game/com.motivado.game.AndroidLauncher'


}




我的主build.gradle


buildscript {



 repositories {


 mavenLocal()


 mavenCentral()


 maven { url"https://plugins.gradle.org/m2/" }


 maven { url"https://oss.sonatype.org/content/repositories/snapshots/" }


 jcenter()


 google()


 }


 dependencies {


 classpath 'com.android.tools.build:gradle:3.5.3'



 }


}



allprojects {



 version = '1.0'


 ext {


 appName ="Motivado Game"


 gdxVersion = '1.9.10'


 roboVMVersion = '2.3.8'


 box2DLightsVersion = '1.4'


 ashleyVersion = '1.7.0'


 aiVersion = '1.8.0'


 }



 repositories {


 mavenLocal()


 mavenCentral()


 jcenter()


 google()


 maven { url"https://oss.sonatype.org/content/repositories/snapshots/" }


 maven { url"https://oss.sonatype.org/content/repositories/releases/" }


 }


}



project(":desktop") {


 apply plugin:"java-library"



 dependencies {


 implementation project(":core")


 api"com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"


 api"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"


 api"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"



 }


}



project(":android") {


 apply plugin:"android"



 configurations { natives }



 dependencies {


 implementation project(":core")


 api"com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"


 natives"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"


 natives"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"


 natives"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"


 natives"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"


 natives"com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"


 api"com.badlogicgames.gdx:gdx-box2d:$gdxVersion"


 natives"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"


 natives"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"


 natives"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"


 natives"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"


 natives"com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"



 }


}



project(":core") {


 apply plugin:"java-library"



 dependencies {


 api"com.badlogicgames.gdx:gdx:$gdxVersion"


 api"com.badlogicgames.gdx:gdx-box2d:$gdxVersion"



 }


}



时间: 作者:


apply plugin:"android"




apply plugin: 'com.android.application'



作者:
...