Can we have project without app folder in android studio with everything (java/res/etc) in root

后端 未结 2 1277
天命终不由人
天命终不由人 2021-01-25 21:55

I would like to know that is it possible to have android project without Application module (app or any other name) in Android studio?

Means i can create package and res

2条回答
  •  走了就别回头了
    2021-01-25 22:08

    app/
    build.gradle
    src
    jni
    AndroidManefest.xml
    build.gradle
    settings.gradle

    It's doable and here is how I did it:
    1) Import the eclipse project from Android Studio.
    *if you have a android studio project already, skip this step.
    2) Open build.gradle under sub dir app/ and copy the contents and append/paste it to build.gradle of the top level.
    3) Move all files under app/ to top level.
    *if you don't have these files in top level yet.
    4) Remove settings.gradle.
    * you don't need it any more since you don't have app as a submodules.
    5) Added the following lines to build.gradle

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    
    • Change the dir name to match your layout.
      6) "Clean Projet" and "Rebuild Project"

    Note: If you have other submodules in additional to "app", you will need keep settings.gradle and remove:
    include ":app"
    from it and keep other submodules.

    See my project layout here:

    The final build gradle is a combination of two together:

    Hope it helps.

    David

提交回复
热议问题