【问题标题】:How to install Tween Engine on Android Studio in libGDX?如何在 libGDX 中的 Android Studio 上安装 Tween Engine?
【发布时间】:2016-02-16 10:23:43
【问题描述】:

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

当我打开 build.gradle project(":core") 时,我找不到应该将这段代码放在哪里的依赖项:

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

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

project(":core") {
...

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

这是我在 Gradle 构建日志中遇到的错误:

错误:(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 Engine 在我的 libGDX And​​roid Studio 上运行,我还应该做些什么?

Android 分级:

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")
                        }
                    }
                }
            }
        }
    }
}

核心分级:

apply plugin: "java"

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

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


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


}

【问题讨论】:

  • 您应该更改您的根 build.gradle,而不是特定模块

标签: libgdx tween


【解决方案1】:

这是一个解决方案:

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

【讨论】:

  • 找不到依赖部分,我在第一篇文章中添加了核心和android代码。
  • 仔细阅读: 2. 打开您的项目文件夹,找到build.gradle 文件——这是一个根构建。它不位于 android 或 core 文件夹中,而是位于项目的根目录中
  • 谢谢,现在我明白了。但我不确定 Tween Engine 是否有效。我无法在我的班级中实现 TweenAccessor。
  • 有什么错误吗?更改后您的项目同步成功了吗?
  • 错误:任务 ':core:compileJava' 执行失败。 > 编译失败;有关详细信息,请参阅编译器错误输出。 // 当我重建项目时。
【解决方案2】:

对我来说其他答案的进一步变化:

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

到:

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

成功了。 (显然你的文件名可能不同(例如末尾没有2))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2012-06-26
    • 2015-12-19
    相关资源
    最近更新 更多