"No tests were found" for Android Studio - android

I'm just migrated from Eclipse. My project keeps the old structure like below
projRoot\
src\
res\
...
AndroidManifest.xml
tests
build.gradle
Here's content of build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests/src')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
testApplicationId 'com.xxx.yyy.test'
testInstrumentationRunner 'android.test.InstrumentationTestRunner'
testHandleProfiling true
testFunctionalTest true
}
}
I'm on Android Studio 0.8 beta, Gradle 1.12, I tried every possible solution found all over SO and google without any success.
Anyone can help out? Thanks.
In addition, where can I know the current version of Android Gradle plugin?

For test source set structure, follow this link. It is mentioned that test source sets should be setup as follows:
for local unit tests: module-name/src/test/java/
for android instrumentation tests: module-name/src/androidTest/java/
In case it's still doesn't work. Android Studio may encounter sometimes issues with the recognition of the tests. And the workaround would be to run local tests by using the command line:
./gradlew testVariantNameUnitTest
Once the command is run. You can go back to Android Studio and run the tests and it should work. You can find more on running tests using command line on this link.
Hope this helps.

Related

How to build and run android project with gradle in eclipse

Hello i build an android app using gradle in eclipse. I allways build the project in command line using gradle. Now i try to build and run it in eclipse on android device emulator. In eclipse i don't know how can i build the project with gradle an run it on android emulator device. Please i need help.
You can find my buil.gradle file bellow
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':appcompat_v7')
compile "org.igniterealtime.smack:smack-android:4.1.0-rc1"
compile "org.igniterealtime.smack:smack-tcp:4.1.0-rc1"
// optional features
compile "org.igniterealtime.smack:smack-android-extensions:4.1.0-rc1"
}
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
}
android {
lintOptions{
abortOnError false
}
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
}
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')
}
}
Did you try adding the gradle eclipse plug-in
apply plugin: "eclipse"
And then generate the eclipse project from build.gradle by calling
gradle eclipse
You also should install the "Gradle IDE Pack" from the eclipse marketplace (Help -> Eclipse Marketplace...).

how to integrate pullToRefresh in android studio

I'm new in gradle and android studion.I made integration from eclipse my project (via export )to gradle project.Almost all libs are compiled fine just one pushToRefresh list don't want to add.Every time gradle show me error like this
java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 4
Please help me to solve this issue.There also my gradle code from main project
apply plugin: 'android'
dependencies {
repositories {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services_lib-mycity')
compile project(':view-paget-indicator-mycity')
compile project(':facebook-sdk-mycity')
compile project(':Android-PullToRefresh-master:extras:PullToRefreshListFragment')
compile project(':Android-PullToRefresh-master:library')
}
}
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
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')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Thanks
Try to add to the build.gradle these lines after buildToolsVersion:
defaultConfig {
minSdkVersion 4 //or your minsdk
targetSdkVersion 19
}
Gradle overrides some values in your Manifest, for example the minSdk.
If this value is not specified, gradle uses the value = 1 (and the pulltoRefresh library uses minSdk=4)

How to make Android Studio read (minSdkVersion from) AndroidManifest.xml correctly?

I have an Android project which was created in Eclipse, exported as Gradle build file, then opened in Android Studio. (Yes, it would be far easier to create a clean project in AS but I need to support the current project structure.)
Otherwise things are now mostly working, but there's still some stuff to be ironed out.
In every Activity class, AS shows this error: Class requires API level 1 (current min is -1): Activity
Alt+Enter offers to fix that with a #TargetApi annotation... but why should I have to do that, when in AndroidManifest.xml, we have:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
AndroidManifest.xml is located at project root (Eclipse default?). Looks like Android Studio is not correctly reading the settings in it. The project still compiles fine though.
Any idea how to get rid of the error?
The Eclipse-generated build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
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')
}
}
Try to add to the build.gradle following lines right after buildToolsVersion:
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
}

built flavors of a project

I want to build different flavors of a project (only the res folders have different contents), but it doesn't work.
So here is my build.gradle file (like in this question Custom old Android project structure in Gradle):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project('<path>:actionbarsherlock')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release{
packageNameSuffix ".release"
}
android.sourceSets.flavor1 {
res.srcDir = ['res_flavor1']
}
android.sourceSets.flavor2 {
res.srcDir = ['res_flavor2']
}
productFlavors {
flavor1 {
packageName "androidstudio.test.flavor1"
}
flavor2 {
packageName "androidstudio.test.flavor2"
}
}
}
}
Structure of my folders (I want to change just one layout for each flavor):
my_project
src
res
res_flavor1
res_flavor2
I don't see any changes in the build variants, so when I export an apk its of the main directory (androidstudio.test).
Whats wrong with my file?
My Android Studio Version: 0.1.3.
If you need more information, say what and I will post it.
Thanks!
[EDIT]
#Greg:
I changed the res-folder in my question above, but I still get just two APKs in my project "out" folder (path: "out/production/androidstudio.test"): androidstudio.test.apk and androidstudio.test.unaligned.apk (the project and module name is: android.studio - I edited this names in my question above, otherwise its a bit confusing :)).
The different buildTypes should be generated automatically, shouldn't they? And to generate them I go to: Run -> Run "androidstudio.test".
I also looked in the log files of android-studio, but there is no error.
Here is a Screenshot of my Package Explorer, perhaps I made here a mistake?
I really don't understand why the flavors aren't build.
You want to be setting res.srcDirs = ['res_flavor1'] instead of resources.srcDir = ['res_flavor1']. The naming is a bit confusing, but the "resources" directory isn't the same as the Android "res" directory.

How to build Sherlock with gradle from command line?

I'm trying to build Sherlock with Gradle from command line. I'm trying to build the Sherlock library itself. Here's what I did:
1) I used Eclipse File|Export|Create Gradle build files and got me a build.gradle for Sherlock.
2) Now I go to sherlock/actionbarsherlock and do gradle build from command line
3) Now it starts building fine but then it gives errors as if the Java Compiler version is 1.5. It complains about overriding interface methods.
C:\sherlock\actionbarsherlock\src\com\actionbarsherlock\app\Sherlock
Fragment.java:22: error: method does not override or implement a method from a supertype
#Override
I wonder why is it so?
In Android Studio it builds fine but I can't build from the command line.
Here's my build.gradle for Sherlock but then it's generated by Eclipse I changed nothing.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 7
targetSdkVersion 15
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I think you missed to add it to the dependecies
dependencies {
compile files('libs/android-support-v4.jar')
}

Categories

Resources