java - 在 linux 上导入 gradle 后没有项目模块

标签 java android linux intellij-idea gradle

我有以下根 build.gradle 文件:

 buildscript {
        repositories {
            mavenCentral()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.1.3'
        }
    }

    allprojects {
        apply plugin: "eclipse"
        apply plugin: "idea"

        version = '1.0'
        ext {
            appName = "my_project"
            gdxVersion = '1.5.4'
            roboVMVersion = '1.12.0'
            box2DLightsVersion = '1.3'
            ashleyVersion = '1.7.0'
            aiVersion = '1.8.0'
        }

        repositories {
            mavenCentral()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
            maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        }
    }

    project(":desktop") {
        apply plugin: "java"

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

    }

    project(":android") {
        apply plugin: "android"

        configurations { natives }

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

    project(":core") {
        apply plugin: 'scala'
        apply plugin: "java"
        apply plugin: 'idea'

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

    }

和每个模块的:

核心

   //apply plugin: 'scala'
    apply plugin: "java"
    sourceCompatibility = 1.7
    [compileScala, compileTestScala, compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

    sourceSets {
        main {
            scala.srcDirs = ['src/main/java']
            java.srcDirs = []
        }
        test {
            scala.srcDirs = ['src/test/java']
            java.srcDirs = []
        }
    }

    compileTestScala {
        scalaCompileOptions.fork = true
        scalaCompileOptions.forkOptions.jvmArgs = ['-XX:MaxPermSize=2048m']
        scalaCompileOptions.additionalParameters = [
                "-feature",
                "-language:reflectiveCalls", // used for config structural typing
                "-language:postfixOps"
        ]
    }

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

    dependencies {
    }

桌面

 apply plugin: "java"
    sourceCompatibility = 1.7
    //sourceCompatibility = JavaVersion.VERSION_1_8
    //sourceSets.main.java.srcDirs = ["src/"]

    sourceSets {
        main {
            java {
                srcDirs = ["src/main/java"]
            }
        }
        test {
            java {
                srcDirs = ["src/test/java"]
            }
        }
    }

    project.ext.mainClassName = "com.example.my_project.desktop.DesktopLauncher"
    project.ext.assetsDir = new File("../android/assets");
    task run(dependsOn: classes, type: JavaExec) {
        main = project.mainClassName
        classpath = sourceSets.main.runtimeClasspath
        standardInput = System.in
        workingDir = project.assetsDir
        ignoreExitValue = true
    }
    task dist(type: Jar) {
        from files(sourceSets.main.output.classesDir)
        from files(sourceSets.main.output.resourcesDir)
        from { configurations.compile.collect { zipTree(it) } }
        from files(project.assetsDir);

        manifest {
            attributes 'Main-Class': project.mainClassName
        }
    }
    dist.dependsOn classes
    eclipse {
        project {
            name = appName + "-desktop"
            linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
        }
    }
    task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
        doLast {
            def classpath = new XmlParser().parse(file(".classpath"))
            new Node(classpath, "classpathentry", [kind: 'src', path: 'assets']);
            def writer = new FileWriter(file(".classpath"))
            def printer = new XmlNodePrinter(new PrintWriter(writer))
            printer.setPreserveWhitespace(true)
            printer.print(classpath)
        }
    }
    dependencies {
    }

安卓

 android {
        buildToolsVersion "23.0.3"
        compileSdkVersion 23
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src/main/java']
                resources.srcDirs = ['src/main/resources']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
                jniLibs.srcDirs = ['libs']
            }

            instrumentTest.setRoot('tests')
        }
        defaultConfig {
            applicationId "com.example.my_project.android"
            minSdkVersion 10
            targetSdkVersion 23
            multiDexEnabled true
        }

        dexOptions {
            incremental true
            javaMaxHeapSize "4g"
        }

        lintOptions {
            abortOnError false
        }
    }
    // 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")
                            }
                        }
                    }
                }
            }
        }
    }
    dependencies {
    }

在我的 windows 机器上,它构建了所有三个模块——核心、桌面和 android,但在 linux 上,除了项目根文件夹之外,在项目结构中没有找到任何模块。行为因平台类型而异的原因可能是什么?

我正在使用: 想法 2016.3, gradle 3.2.1(用于项目默认的 gradle 包装器), 常规 2.4.7, jvm 1.7.0_80

最佳答案

问题是android sdk应该事先设置好。

关于java - 在 linux 上导入 gradle 后没有项目模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40975772/

相关文章:

java - 在 Android 代码中搜索电话号码

linux - sed 删除找到的最后一个匹配项之上的所有内容

java - 如何在 Spring UriComponentsBuilder 中对逗号进行编码?

java - 为什么我的线程不同步?

java - 当我们手动将它作为 Windows 服务运行时,如何更改 tomcat 的 java_opts?

java - 如何获取 Multipart 文件的真实扩展类型

java - Android Java - DataInputStream 从套接字到字符串

android - 如何从设计支持 android 在选项卡布局中嵌入字体

c - C 中的管道 - 我必须使用 fork 吗?

c - 不同ip的服务器