如何在包内添加目录?

时间:2018-06-29 12:38:56

标签: android android-studio gradle

我这里有一个Android项目,该项目由*.cpp文件夹中的本机部分(*.hjni文件)组成。在其中,有一个名为modules的程序包,其中包含多个目录。我想在modules包中添加自己的模块以及另一个子目录,但是我只能添加包:

Adding a package to a package in Android Studio

由于我认为Android Studio在这方面限制了我,所以我在Android Studio外部添加了该文件夹,删除了.idea文件夹和*.iml文件,并重新同步了Gradle。

strong>但是,我的新文件夹仍然是一个包(类似于模块文件夹的图标),而不是像其他目录一样的简单子目录:

Added folder becomes a package after Gradle sync

我希望我的术语正确,并且对软件包和目录没有足够的了解。实际上,其他目录是正确的,但是在Gradle文件中找不到任何可以解释此行为的内容。

以下是lib的build.gradle

apply plugin: 'com.android.library'

android {
    // If you want to use the debugger for JNI code, you want to compile this lib-project in Debug!
    // And due to gradle limitations/bugs, the best way is to always compile it in debug.
    // See https://code.google.com/p/android/issues/detail?id=52962
    // and http://stackoverflow.com/questions/27277433/why-does-gradle-build-my-module-in-release-mode-when-the-app-is-in-debug
    // defaultPublishConfig "debug"
    compileSdkVersion 25
    buildToolsVersion '27.0.3'

    defaultConfig {
        compileSdkVersion 25
        buildToolsVersion "27.0.3"
        minSdkVersion 14
        externalNativeBuild {
            ndkBuild {
                arguments "-j2"
            }
        }
        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your APK.
            abiFilters 'armeabi-v7a'
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            java {
                srcDirs('src/main/java', 'src/jni/SDL2-2.0.5/android-project/src')
            }
        }
    }
    externalNativeBuild {
        ndkBuild {
            path "src/jni/Android.mk"
        }
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    api fileTree(dir: 'libs', include: ['*.jar', '*.arr'])
    api 'com.android.support:appcompat-v7:25.2.0'
    api 'com.google.android.gms:play-services-ads:11.0.4'
}

整个项目的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我将新文件夹中的新文件添加到Android.mk中,就像添加了其他文件一样。

如何向该modules文件夹添加目录而不是软件包?

更多信息:这是LÖVE(love2d)游戏框架的Android端口。我正在使用Mac。

0 个答案:

没有答案