如何在libGDX中的Android Studio上安装Tween引擎?

时间:2016-02-16 10:23:43

标签: libgdx tween

我下载了两个jar文件,并将它们放在libs文件夹中。

当我打开build.gradle项目(“:core”)时,我无法找到应该放入此代码的依赖项:

compile fileTree(dir: '../libs', include: '*.jar')

它看起来应该是这样但我在build.gradle中找不到它:

project(":core") {
...

dependencies {
    ...
    compile fileTree(dir: '../libs', include: '*.jar')
}
}

这是我在Gradle Build Log中得到的错误:

错误:(8,1)评估根项目'runningame'时出现问题。

  

无法在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@72594296上找到参数[directory'../libs']的方法compile()。

我的jar文件位于此处:

C:\Users\zfilfah\AndroidStudioProjects\game\core\build\libs

还制作了一个新文件夹,用于测试它是否有效:

C:\Users\zfilfah\AndroidStudioProjects\game\core\libs

我错过了什么?我还应该做些什么才能使Tween引擎在我的libGDX And​​roid 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")
                        }
                    }
                }
            }
        }
    }
}

Core gradle:

apply plugin: "java"

sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"


}

2 个答案:

答案 0 :(得分:1)

这是一个解决方案:

  1. 将两个罐放入libs文件夹
  2. 打开项目文件夹并找到build.gradle文件 - 这是根构建
  3. 在" core"的依赖关系部分下添加此行compile fileTree(dir: '../libs', include: '*.jar')和" android" 项目。
  4. 将这两个补间引擎jar添加到IDE中的模块依赖项中。
  5. 使用gradle同步项目。

答案 1 :(得分:0)

对于我改变的其他答案:

compile fileTree(dir: 'libs', include: '*.jar')

为:

compile fileTree(dir: '../libs/tween-engine-api-6.3.3 2', include: '*.jar')

做了这个伎俩。 (显然你的文件名可能不同(例如最后没有2))