Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Eliminating the unused "app/" directory path in Android Studio Projects

Author: Ian Darwin
Published? true
FormatLanguage: WikiFormat

Problem:

You do not like the useless "app/" directory indirection that Android Studio sets up for every new project.

Solution:

Rearrange the project structure to eliminate it, and juggle a few config files.

Discussion:

First, understand that the build tools and version numbers change almost daily in Android land, so everything here must be treated as a snapshot that worked today.

Second, suppose there actually is a reason for having the useless-appearing app/ directory level? Well, you can always move back later.

So, here is the plan:

  • cd into the top-level project (where app is located)
  • Move app/src to .
  • If you think you might also want to use Eclipse (see <<r5203>>),

move src/main/res to . and move src/main/AndroidManifest.xml to .

  • Move app/build.gradle to . then add a few entries so it looks like <<fig-build-gradle>>
  • Delete the app subdirectory
  • Delete file gradle.properties
  • Delete file settings.gradle
  • Take a deep breath, and open the project in Gradle Studio.

fig-build-gradle .Merged build.gradle


apply plugin: 'com.android.application'

buildscript {

repositories {
	jcenter()
}
dependencies {
	classpath 'com.android.tools.build:gradle:2.3.3'
}

}

android {

compileSdkVersion 26
buildToolsVersion "25"
defaultConfig {
	applicationId "com.darwinsys.expenses"
	minSdkVersion 15
	targetSdkVersion 26
	versionCode 1
	versionName "1.0"
}
sourceSets {
	// This is for Eclipse compat
	main {
		res.srcDirs = ['res']
		manifest.srcFile 'AndroidManifest.xml'
	}
}

}

repositories {

jcenter()
mavenCentral()

}

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
	exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'

}


When I applied this set of changes to my "Expenses" demo project (at https://github.com/IanDarwin/Expenses[]), the GIT log was fairly robust (see <<fig-git-log>>).

fig-git-log .Git Log from Expenses project reorganization


LAPTOP-Expenses $ git commit [master 2b1ee87] Nuke *useless* app/ directory indirection.

40 files changed, 59 insertions(+), 78 deletions(-)
create mode 100644 .idea/vcs.xml
rename app/src/main/AndroidManifest.xml => AndroidManifest.xml (100%)
delete mode 100644 app/.gitignore
delete mode 100644 app/build.gradle
rewrite build.gradle (95%)
delete mode 100644 gradle.properties
rename app/proguard-rules.pro => proguard-rules.pro (100%)
rename {app/src/main/res => res}/drawable-hdpi/ic_camera.png (100%)
rename {app/src/main/res => res}/drawable-mdpi/ic_camera.png (100%)
rename {app/src/main/res => res}/drawable-xhdpi/ic_camera.png (100%)
rename {app/src/main/res => res}/drawable-xxhdpi/ic_camera.png (100%)
rename {app/src/main/res => res}/layout-w900dp/expenseitem_list.xml (100%)
rename {app/src/main/res => res}/layout/activity_expenseitem_detail.xml (100%)
rename {app/src/main/res => res}/layout/activity_expenseitem_list.xml (100%)
rename {app/src/main/res => res}/layout/expenseitem_detail.xml (100%)
rename {app/src/main/res => res}/layout/expenseitem_list.xml (100%)
rename {app/src/main/res => res}/layout/expenseitem_list_content.xml (100%)
rename {app/src/main/res => res}/layout/expenses_form.xml (100%)
rename {app/src/main/res => res}/mipmap-hdpi/ic_app.png (100%)
rename {app/src/main/res => res}/mipmap-hdpi/ic_launcher.png (100%)
rename {app/src/main/res => res}/mipmap-mdpi/ic_app.png (100%)
rename {app/src/main/res => res}/mipmap-mdpi/ic_launcher.png (100%)
rename {app/src/main/res => res}/mipmap-xhdpi/ic_app.png (100%)
rename {app/src/main/res => res}/mipmap-xhdpi/ic_launcher.png (100%)
rename {app/src/main/res => res}/mipmap-xxhdpi/ic_app.png (100%)
rename {app/src/main/res => res}/mipmap-xxhdpi/ic_launcher.png (100%)
rename {app/src/main/res => res}/values/colors.xml (100%)
rename {app/src/main/res => res}/values/dimens.xml (100%)
rename {app/src/main/res => res}/values/strings.xml (100%)
rename {app/src/main/res => res}/values/styles.xml (100%)
delete mode 100644 settings.gradle
rename {app/src => src}/androidTest/java/com/darwinsys/expenses/ExampleInstrumentedTest.java (100%)
rename {app/src => src}/main/java/com/darwinsys/expenses/ExpenseItemDetailActivity.java (100%)
rename {app/src => src}/main/java/com/darwinsys/expenses/ExpenseItemDetailFragment.java (100%)
rename {app/src => src}/main/java/com/darwinsys/expenses/ExpenseItemListActivity.java (100%)
rename {app/src => src}/main/java/com/darwinsys/expenses/dao/ExpenseDao.java (100%)
rename {app/src => src}/main/java/com/darwinsys/expenses/model/ExpenseItem.java (100%)
rename {app/src => src}/test/java/com/darwinsys/expenses/ExampleUnitTest.java (100%)

LAPTOP-Expenses $


Download:

The source code for this project can be downloaded from https://github.com/IanDarwin/Expenses.
No records found.