I have a fully working Android application based on ANT build tools. It is used with Eclipse but I have to make it work with Android Studio as well. I managed to export the project with ADT Gradle Export Tool and the application itself works great. However, I can't get the test project to work.
Here's build.gradle
generated by Eclipse ADT plugin.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
My project structure
.
├── AndroidManifest.xml
├── ant.properties
├── build.gradle
├── build.xml
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── LICENSE
├── local.properties
├── MyApp.iml
├── proguard-project.txt
├── project.properties
├── README.md
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ └── strings.xml
├── src
│ └── com
│ └── example
│ └── myapp
│ └── MainActivity.java
└── tests
├── AndroidManifest.xml
├── ant.properties
├── build.xml
├── proguard-project.txt
├── project.properties
└── src
└── com
└── example
└── myapp
└── MainActivityTest.java
For me it seems that Android Studio is not able to detect tests/src/PACKAGE
as a package. It is classified as casual directories instead.
I would really appreciate any hints.
EDIT:
If tests/src
is renamed into tests/java
everything works. But this is not a solution since tests will stop working with ANT and/or Eclipse.