So, the title pretty much sums up my problem. Anyone know how to fix it? Last time I build apk, it work fine on AS 2.X, but, I'm now developing with Kotlin so, I have to use AS 3.0.
I use AS 3.0 Canary 7 (This project is a fresh project)
This is my dummy class in my library (Stored in "domain".library.mylibrary)
class Test {
fun hello(): String {
return "hello"
}
}
And this is my (mylibrary) gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" //Declared in project level gradle: ext.kotlin_version = '1.1.3-2'
}
My gradlew.bat clean build --info log: https://pastebin.com/bfTZ5s4e
Android Studio does not generate a jar by default, but rather an AAR file. If you want to get a jar output, you need to implement apply plugin: 'maven-publish' on top of your mylibrary/gradle.build file and read the following document: Chapter 36. Maven Publishing (new)
Another note, is that I would suggest you not to use ProGuard directly on your release artifact, but rather provide a consumer ProGuard file and let the users of your library to handle that task, otherwise they will have a hard time referencing obfuscated code. Read my answer on this here
While the build task may generate an output, it is known that the assemble task (or assembleRelease) is the one that will generate your aar output.
Try running the following command:
./gradlew clean assembleRelease
and check the output in /mylibrary/build/outputs/apk/release/ if I am not mistaken.
I'm playing with Gradle for Android recently... It's powerful but painful at the same time.
Initially, I followed Roboletric sample project, trying to make a gradle-based Android project with Robolectric testing support. After a while, I realise Robolectric doesn't even support API 19. Thus, I remove it from my build.gradle and try to use Junit and Instrumentation tests.
I'm not familiar with either Android or Gradle or Roboletric. I only know that before I removed Robolectirc, whenever I made a build ./gradlew clean build I was able to run all the tests. But now, I have to call ./gradlew connectedAndroidTest in addition to run tests while the build command only calls check but no test is run and thus always show SUCCESSFUL
I have attached my configuration here:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
packageName "com.example"
testPackageName "com.example.tests"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flavorDimensions "AppPackage", "AppEnvironment"
appBasic {
flavorDimension "AppPackage"
}
staging {
flavorDimension "AppEnvironment"
}
production {
flavorDimension "AppEnvironment"
}
}
sourceSets {
androidTest.setRoot('src/test')
androidTestStaging.setRoot('src/testStaging')
androidTestProduction.setRoot('src/testProduction')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
}
By default the connectedAndroidTest task don't run when you run the build task.
By default the check task run when you run the build task.
All you have to do is to add an explicit dependency to run the connectedAndroidTest task when the check task run :
check.dependsOn connectedAndroidTest
Everytime I try to run my tests the console says this:
Running tests
Test running startedTest running failed: Unable to find instrumentation info for:
ComponentInfo{com.employeeappv2.employeeappv2.test/android.test.InstrumentationTestRunner}
Empty test suite.
I've been stuck on this for a while and the solutions I've seen online so far have not helped.
My project structure is set up like this:
*Main Module
-src
*instrumentTest
-java
*main
-java
-manifest
*build.gradle
My build.gradle file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "2.1.0"
testPackageName "login.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/scandit.zip')
compile project(':pullToRefresh')
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1+'
compile 'org.springframework.android:spring-android-rest-template:1.0.1+'
compile 'org.json:json:20090211'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.3.1'
compile 'com.android.support:support-v4:19.1.+'
compile 'com.mcxiaoke.volley:library:1.0.+#aar'
androidTestCompile 'junit:junit:3.8'
}
Do you need to have a separate manifest for your tests directory? If so what would that look like?
Edit: I tried adding a manifest to my instrumentTest directory with no luck. Note that I could not get IntelliJ to resolve the targetPackage name, so it appears red.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.employeeappv2.employeeappv2.src.instrumentTest"
android:versionCode="1"
android:versionName="1.0.0">
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.employeeappv2.employeeappv2.src.main"/>
</manifest>
I had the same error when I tried adding multiDexEnabled true to build.gradle.
I'm adding my experience here, because this is one of the first Google hits when searching with the ... Unable to find ... ComponentInfo ... error message.
In my case adding testInstrumentationRunner like here did the trick:
...
android {
...
defaultConfig {
...
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
}
(I have com.android.tools.build:gradle:1.5.0)
I am using Android Studio 1.1 and the following steps solved this issue for me:
In Run - Edit Configurations - Android Tests
Specify instrumentation runner as android.test.InstrumentationTestRunner
Then in the "Build variants" tool window (on the left), change the test artifact to Android Instrumentation Tests.
No testInstrumentationRunner required in build.gradle and no instrumentation tag required in manifest file.
When I created a new package, Studio created an ApplicationTest class. Using us.myname.mypackage as an example, the following directory structure was created:
app/[myPackage]/src/androidTest/java/us/myname/mypackage/ApplicationTest.class
Initially it worked out of the box. It quit working after I installed product flavors. I subsequently made the following changes to build.gradle:
defaultConfig {
...
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
some prefer
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
(With my current configuration, I have to use ...InstrumentationTestRunner when in debug, and AndroidJUnitRunner while using release build type.)
The above configuration only works with the debug build type. If you wish to use it with release or with a custom build type, you can include the following in build.gradle:
buildTypes {
release {
...
}
debug {
...
}
}
testBuildType "release"
In the Build Variants tab on the lower left side of Studio, make sure you have Android Instrumentation Tests and the correct buildType selected.
I had to do a combination of VikingGlen's answer, Liuting's answer, and this answer. This answer works for Android Studio version 2.1.
Run -> Edit Configurations... -> General -> Specific instrumentation runner (optional): "android.support.test.runner.AndroidJUnitRunner"
In build.gradle (the one with all your dependencies), put this:
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Then it could run tests of this type:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class ApplicationTest {
#Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
#Test
public void login() {
//Open Drawer to click on navigation.
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
.perform(open()); // Open Drawer
}
}
For what it's worth, AS 2.3 got hung up when i created a custom test runner after using the regular test runner. I got the same error as posted in the question.
Deleting the Debug Configurations for ALL Android Instrumented Tests and rebuilding fixed it. I believe the problem lied in the fact you no longer can choose a custom runner in the Debug Configurations because it's most likely built in via gradle.
So the main problem was that when I created an androidTest folder under /src/, it wasn't being picked up by IntelliJ as a source folder for testing (java subdirectory should turn green). I was using IntelliJ 13.0.3 and after upgrading to 13.1.3, all of my troubles went away.
*Note: do not try to add a manifest to your androidTest folder, the Gradle docs specifically state that the manifest should be auto-generated when you create the androidTest folder. The problem for me was that the file wasn't being generated as androidTest wasn't being recognized by IntelliJ/Gradle, thus throwing the no instrumentation error.
I had this problem and fixed it by going to Run -> Edit Configurations -> Green '+' button at the top left -> JUnit
From there, set the 'use the classpath mod...' to 'app' (or your default app name, which is the one that appears to the left of the run (play button) when you run the app)
Finally, put your test class name in the 'class:' textbox. Click apply and okay.
At this point, if the test class doesn't have other errors, it should work.
This is what I noticed in my project, in my app(main) module build.gradle I had the following buildType configuration
buildTypes {
debug {
multiDexEnabled true
}
mock {
initWith(buildTypes.debug)
}
}
testBuildType "mock"
When I used AndroidJUnitRunner as the test runner(both from Android Studio) and as testInstrumentationRunner in build.gradle, tests ran without hitch.
In a submodule that had multiDexEnabled true as defaultConfig
defaultConfig {
multiDexEnabled true
....
}
I ran into the problem of
Test running startedTest running failed: Unable to find instrumentation info for:{mypackage.x.y/android.support.test.runner.AndroidJUnitRunner"}
when I specified AndroidJUnitRunner in IDE and the submodule build.gradle. And this was fixed by specifying MultiDexTestRunner as the test runner in IDE/build.gradle.
To summarize, Use MultiDexTestRunner to run tests when multiDexEnabled true is specified in build.gradle, else use AndroidJUnitRunner as the test runner.
Make sure the app has been uninstalled for all users.
Go to settings -> apps (all apps) -> If your app is there then tap on it -> menu -> uninstall for all users.
My issue was that the app was at one point uninstalled, however still on the device; meaning it was not uninstalled for all users. (Another issue, not sure how to resolve. I'm the only user on my device)
Because of this, the app wouldn't re-install, and the test suite had nothing to run against.
The solution for my problem is to change the method name from
#Test
public void test() {
...
}
to
#Test
public void testSomething() {
...
}
Hope it helps someone.
So I've set up a gradle project with android and tried to get some tests to run. Unfortunately they don't seem to. It's possible that I'm missing something obvious but here goes...
I am running gradle 1.11 and as I understand the documentation that's the new folder (since 0.9 I believe?) that should be used for tests.
So I have my testclass ::
package se.coinhunter.multigradle.test;
import org.junit.Test;
import static org.junit.Assert.*;
public class HelloAndroidTests {
#Test
public void testHelper() {
assertEquals(1,1);
}
}
}
That lives in src/androidTest and here is my build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':MultiGradleSubmodule')
}
This is a multi-project build and the submodule mentioned in the dependencies block is a plain java project that has its' own scource and unit tests running quite smoothly. I was able to specify that it should tell me when it runs its' tests and give me some feedback and that works fine. That was achieved for that project using
test {
testLogging {
events 'started', 'passed'
}
}
in its' build.gradle. I havn't come across anything like this for android projects. The whole project builds and runs, but I either can't get the tests to run, or they're running but I'm not getting any output.
You're using jUnit 4 (package name "org.junit" with #Test annotation). Android gradle only works with jUnit 3 (package name "junit.framework" with no annotations).
Android tests run in the Dalvik virtual machine on a device or emulator so your test class should also extend "AndroidTestCase" (or one of the other junit subclasses in Android - depending on what you're testing).
UPDATED: also add the following to default config:
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testFunctionalTest true
Run the test using
gradle connectedCheck
I'm trying to get the androidTest (instrumentation tests) working for the openScale Android app using the following build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.health.openscale"
testApplicationId "com.health.openscale.test"
minSdkVersion 18
targetSdkVersion 22 // don't set target sdk > 22 otherwise bluetooth le discovery need permission to ACCESS_COARSE_LOCATION
versionCode 22
versionName "1.7 (beta)"
javaCompileOptions {
annotationProcessorOptions { arguments = ["room.schemaLocation":"$projectDir/schemas".toString()] }
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
ext {
supportLibVersion = '27.0.2'
}
dependencies {
implementation "com.android.support:design:${supportLibVersion}"
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
// HelloCharts
implementation 'com.github.lecho:hellocharts-library:1.5.8#aar'
// Simple CSV
implementation 'com.j256.simplecsv:simplecsv:2.2'
// CustomActivityOnCrash
implementation 'cat.ereza:customactivityoncrash:2.2.0'
// Room
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
androidTestImplementation 'android.arch.persistence.room:testing:1.0.0'
// Local unit tests
testImplementation 'junit:junit:4.12'
// Instrumented unit tests
androidTestImplementation "com.android.support:support-annotations:${supportLibVersion}"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
There's a single test file under android_app/app/src/androidTest/java/com.health.openscale/DatabaseTest.java
I'm using the command ./gradlew --no-daemon --no-build-cache -i connectedDebugAndroidTest to build and run the tests and it works fine the first time: both tests in the file are executed and pass.
But now, if I change the test file (small change to trigger a rebuild) and run the above command again I get the following output:
...
Putting task artifact state for task ':app:compileDebugAndroidTestJavaWithJavac' into context took 0.0 secs.
file or directory '/<path>/android_app/app/src/androidTestDebug/java', not found
Executing task ':app:compileDebugAndroidTestJavaWithJavac' (up-to-date check took 0.007 secs) due to:
Input property 'source' file /<path>/android_app/app/src/androidTest/java/com.health.openscale/DatabaseTest.java has changed.
Compiling with source level 1.7 and target level 1.7.
...
Putting task artifact state for task ':app:transformClassesWithDexBuilderForDebugAndroidTest' into context took 0.0 secs.
Executing task ':app:transformClassesWithDexBuilderForDebugAndroidTest' (up-to-date check took 0.024 secs) due to:
Input property '$3' file /<path>/android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class has been removed.
Transform inputs calculations based on following changes
/<path>/android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class:REMOVED
...
Starting 0 tests on Nexus_5X_API_26(AVD) - 8.0.0
[XmlResultReporter]: XML test result file generated at /<path>/android_app/app/build/outputs/androidTest-results/connected/TEST-Nexus_5X_API_26(AVD) - 8.0.0-app-.xml. Total tests 0,
com.android.builder.testing.ConnectedDevice > No tests found.[Nexus_5X_API_26(AVD) - 8.0.0] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
[XmlResultReporter]: XML test result file generated at /<path>/android_app/app/build/outputs/androidTest-results/connected/TEST-Nexus_5X_API_26(AVD) - 8.0.0-app-.xml. Total tests 1, failure 1,
...
Does anyone know why the rebuild doesn't work? Why is the class removed from the build?
I have verified with the APK analyzer in Android studio that the DatabaseTest class is indeed missing from the APK after the rebuild.
It seems that moving the test case from .../com.health.openscale/DatabaseTest.java to .../com/health/openscale/DatabaseTest.java fixed the problem.