0

I have an Android project here, that consists of native parts (*.cpp and *.h files) within the jni folder. In this, there is a package called modules that has several directories in it. I'd like to add my own module in the modules package with another sub-directory, however I can only add packages:

Adding a package to a package in Android Studio

Since I believe Android Studio limits me on that point, I added the folder outside of Android Studio, removed my .idea folder and the *.iml files and re-synced Gradle. However, my new folder is still a package (icon like the module folder) and not a simple sub-directory like the other directories:

Added folder becomes a package after Gradle sync

I hope I got the terminology right and don't lack enough understanding about packages and directories. De facto, the other directories are correct, but I could not find anything within the Gradle files that would explain this behaviour.

Here is the build.gradle of the lib:

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'
}

And the build.gradle of the whole project:

// 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
}

I added my new files in my new folder to the Android.mk like the other files were added.

How can I add a directory instead of a package to that modules folder?

Further information: This is the Android port of the LÖVE (love2d) game framework. I'm using a Mac.

Martin Braun
  • 10,906
  • 9
  • 64
  • 105
  • @cricket_007 As I said in my question already, I tried this, and it's still added as package. – Martin Braun Jun 29 '18 at 12:43
  • What if you copied one of the other directories, then cleaned out all the files in it? – OneCricketeer Jun 29 '18 at 12:45
  • Copying a folder with a new name results in a package, too. I need to know how Gradle comes to the decision that those folders are directories instead of packages to be able to tell Gradle to do the same with my new folder. – Martin Braun Jun 29 '18 at 12:47
  • Is this project under public source control? If yes, could you add a link? I guess the root of your problem is caused by another file, so I would like to check the whole project structure (maybe even test on my own system). – Lukas Körfer Jun 29 '18 at 13:22
  • 1
    Why do you want to create a "folder" in the first place? If it's for storing non-java files, then you should move the files to the `res` folder. The `src` folder should *only* contain source code – vatbub Jun 29 '18 at 13:26
  • @lu.koerfer Yes it is. This is my fork containing the problem: https://bitbucket.org/MartyMaro/love2d-admob-unityads-inappbilling-gameservices-android/src/master/ and this is the original repo: https://bitbucket.org/MartinFelis/love-android-sdl2/src/master/ my own fork cannot compile, because some files are not converted from iOS yet, but it should help to illustrate the issue. – Martin Braun Jun 29 '18 at 14:58
  • @vatbub I want to create a directory, not folder (different in AS) and I want to do it, because I want to add a new module to this framework. I didn't create the other stuff and to stay aligned with the rest I want to do the same like the original programmer of the port. Cpp and h files are native source files, why exactly should they be located in the res folder at all? As I understand they need to be located within the jni folder at least. – Martin Braun Jun 29 '18 at 15:52
  • UPDATE: It seems that the issue is gone when the repo is pulled to a clean folder without other files. It seems I forgot to remove any file that causes the issue allowing me to recognise the folder as directory. I still want to know why this is happening, though. You can reproduce the issue by trying to add another directory to the folder. The folder is at: `/love/src/jni/love/src/module` – Martin Braun Jun 29 '18 at 22:03
  • @modiX, Sry, I forgot about your C++ files, they should obviously reside in the `jni` folder. What I was talking about were resource files like images or xml files which are not source code – vatbub Jun 29 '18 at 22:11

0 Answers0