如何在 libGDX 的 Android Studio 上安装 Tween Engine?
How to install Tween Engine on Android Studio in libGDX?
我已经下载了两个jar 文件并将它们放在libs 文件夹中。
当我打开 build.gradle 项目 (":core") 时,我找不到应该将此代码放入的依赖项:
compile fileTree(dir: '../libs', include: '*.jar')
它应该看起来像这样,但我在 build.gradle 中找不到它:
project(":core") {
...
dependencies {
...
compile fileTree(dir: '../libs', include: '*.jar')
}
}
这是我在 Gradle 构建日志中得到的错误:
错误:(8, 1) 评估根项目时出现问题 'runningame'。
Could not find method compile() for arguments [directory '../libs'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@72594296.
我的 jar 文件位于:
C:\Users\zfilfah\AndroidStudioProjects\game\core\build\libs
还创建了一个新文件夹用于测试它是否有效:
C:\Users\zfilfah\AndroidStudioProjects\game\core\libs
我错过了什么?我还应该做些什么才能让 Tween Engine 在我的 libGDX Android Studio 上工作?
Android gradle:
android {
buildToolsVersion "23.0.2"
compileSdkVersion 23
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
defaultConfig {
applicationId "com.mygdx.game"
minSdkVersion 8
targetSdkVersion 23
}
}
// 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() {
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"
}
}
}
}
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.mygdx.game/com.mygdx.game.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
核心gradle:
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
解决方法如下:
- 将两个 jar 放入 libs 文件夹
- 打开您的项目文件夹并找到
build.gradle
文件 -- 这是根构建
- 在 "core" 和 "android" 的依赖部分下添加此行
compile fileTree(dir: '../libs', include: '*.jar')
项目。
- 将这 2 个补间引擎 jar 添加到 IDE 中的模块依赖项。
- 与 gradle.
同步项目
进一步为我更改其他答案:
compile fileTree(dir: 'libs', include: '*.jar')
至:
compile fileTree(dir: '../libs/tween-engine-api-6.3.3 2', include: '*.jar')
成功了。 (显然你的文件名可能不同(例如末尾没有 2
))
我已经下载了两个jar 文件并将它们放在libs 文件夹中。
当我打开 build.gradle 项目 (":core") 时,我找不到应该将此代码放入的依赖项:
compile fileTree(dir: '../libs', include: '*.jar')
它应该看起来像这样,但我在 build.gradle 中找不到它:
project(":core") {
...
dependencies {
...
compile fileTree(dir: '../libs', include: '*.jar')
}
}
这是我在 Gradle 构建日志中得到的错误:
错误:(8, 1) 评估根项目时出现问题 'runningame'。
Could not find method compile() for arguments [directory '../libs'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@72594296.
我的 jar 文件位于:
C:\Users\zfilfah\AndroidStudioProjects\game\core\build\libs
还创建了一个新文件夹用于测试它是否有效:
C:\Users\zfilfah\AndroidStudioProjects\game\core\libs
我错过了什么?我还应该做些什么才能让 Tween Engine 在我的 libGDX Android Studio 上工作?
Android gradle:
android {
buildToolsVersion "23.0.2"
compileSdkVersion 23
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
instrumentTest.setRoot('tests')
}
defaultConfig {
applicationId "com.mygdx.game"
minSdkVersion 8
targetSdkVersion 23
}
}
// 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() {
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"
}
}
}
}
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.mygdx.game/com.mygdx.game.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
核心gradle:
apply plugin: "java"
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-core"
}
解决方法如下:
- 将两个 jar 放入 libs 文件夹
- 打开您的项目文件夹并找到
build.gradle
文件 -- 这是根构建 - 在 "core" 和 "android" 的依赖部分下添加此行
compile fileTree(dir: '../libs', include: '*.jar')
项目。 - 将这 2 个补间引擎 jar 添加到 IDE 中的模块依赖项。
- 与 gradle. 同步项目
进一步为我更改其他答案:
compile fileTree(dir: 'libs', include: '*.jar')
至:
compile fileTree(dir: '../libs/tween-engine-api-6.3.3 2', include: '*.jar')
成功了。 (显然你的文件名可能不同(例如末尾没有 2
))