I am currently trying to migrate from Android Studio to Intellij.
The problem arises when I try to run my code through unit tests. A method in the code under test calls Log.e and an exception is thrown in Intellij IDE. The same code runs fine in Android Studio. Probably my project settings may configured incorrectly in Intellij. Any one knows where to look for the problem?
java.lang.RuntimeException: Stub!
at android.util.Log.e(Log.java:31)
My Intellij command when running the unit test.
D:\software\Java\jdk1.8.0_181\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576
"-javaagent:D:\software\IntelliJ IDEA Community Edition 2018.2.2\lib\idea_rt.jar=4006:D:\software\IntelliJ IDEA Community Edition 2019.2.2\bin"
-Dfile.encoding=UTF-8
-classpath
"D:\software\IntelliJ IDEA Community Edition 2018.2.2\lib\idea_rt.jar;
D:\software\IntelliJ IDEA Community Edition 2018.2.2\plugins\junit\lib\junit-rt.jar;
D:\software\IntelliJ IDEA Community Edition 2018.2.2\plugins\junit\lib\junit5-rt.jar;
D:\software\Android\sdk\platforms\android-28\android.jar;
D:\software\Android\sdk\platforms\android-28\data\res;
D:\software\Android\sdk\platforms\android-27\data\res;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\intermediates\classes\debug;
D:\software\Android\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy-agent\1.7.9\a6c65f9da7f467ee1f02ff2841ffd3155aee2fc9\byte-buddy-agent-1.7.9.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\runner-1.0.2.aar\d44dda11e7de1711127415e572906e3c\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.objenesis\objenesis\2.6\639033469776fd37c08358c6b92a4761feb2af4b\objenesis-2.6.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.0\edf3f7bfb84a7521d0599efa3b0113a0ee90f85\common-1.1.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\27.1.1\39ded76b5e1ce1c5b2688e1d25cdc20ecee32007\support-annotations-27.1.1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-27.1.1.aar\87b44b5092008154f1171a969696f102\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\5e64a504ec19504fa9b2687a61b079c4\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\5e64a504ec19504fa9b2687a61b079c4\res;
D:\software\Android\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy\1.7.9\51218a01a882c04d0aba8c028179cce488bbcb58\byte-buddy-1.7.9.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.0.aar\8d37b7feb2744759cd91b03ad94efb30\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.mockito\mockito-core\2.15.0\b84bfbbc29cd22c9529409627af6ea2897f4fa85\mockito-core-2.15.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.nhaarman\mockito-kotlin\1.5.0\25faa884f76375f76cdbd6651c4cebcde36d4117\mockito-kotlin-1.5.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.squareup\javawriter\2.1.1\67ff45d9ae02e583d0f9b3432a5ebbe05c30c966\javawriter-2.1.1.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.github.kotlin-graphics\kotlin-unsigned\v2.1\52408e5d299c5d1fb669188dae56fa5bb37cbc12\kotlin-unsigned-v2.1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-27.1.1.aar\8949c790c8f1bf421289f293aa4e1cc2\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\1c49103dd8f3bd81aa06fd4de90258d6\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\1c49103dd8f3bd81aa06fd4de90258d6\res;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-utils-27.1.1.aar\fb3bae07f3360874234d36f26caa5ebb\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.google.code.findbugs\jsr305\2.0.1\516c03b21d50a644d538de0f0369c620989cd8f0\jsr305-2.0.1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\espresso-core-3.0.2.aar\369dec0c3f47cc8d75f961fddc94d0f7\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject\1\6975da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-fragment-27.1.1.aar\0464588052e7fe27a8be9d866a5cd81f\jars\classes.jar;
D:\software\Android\.gradle\caches\modul:es-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\4aa45f99c024430a3ccf7c0e257fb60a\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\monitor-1.0.2.aar\94d037806c32cc9e5663a80cfb787b67\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\2668a362e92dc09e5e5a2ec0e09458ea\res;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\2668a362e92dc09e5e5a2ec0e09458ea\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\espresso-idling-resource-3.0.2.aar\3b7ac85279e2aa734ba776a985e5273e\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.2.30\9758025a415ee400e1f90ff222bcfec247779133\kotlin-reflect-1.2.30.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.2.30\2dfac33f8b4e92c9dd1422cd286834701a6f6d6\kotlin-stdlib-1.2.30.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.0.aar\8c471aa13e8c6e412a4748be6e503cbc\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-library\1.3\4785a3c21320980282f9f33d0d1264a69040538f\hamcrest-library-1.3.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-integration\1.3\5de0c73fef18917cd85d0ab70bb23818685e4dfd\hamcrest-integration-1.3.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.0\8007981f7d7540d89cd18471b8e5dcd2b4f99167\common-1.1.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.2.30\ca12c47fc1e3a7316067b2a51e2f214745ebf8c5\kotlin-stdlib-jdk7-1.2.30.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\net.sf.kxml\kxml2\2.3.0\ccbc77a5fd907ef863c29f3596c6f54ffa4e9442\kxml2-2.3.0.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\f827adbdf97ad86b4140dcb5e1073a50\jars\classes.jar;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\intermediates\sourceFolderJavaResources\test\debug;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\intermediates\unitTestConfig\test\debug;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\tmp\kotlin-classes\debugUnitTest;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\intermediates\sourceFolderJavaResources\debug;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\tmp\kotlin-classes\debug;
D:\code\android\MyProjectAndroid\myProjectandroidgc\build\generated\mockable-android-26.default-values.v3.jar"
com.intellij.rt.execution.junit.JUnitStarter
-ideVersion5 #w#C:\Users\cjf12\AppData\Local\Temp\idea_working_dirs_junit.tmp #C:\Users\cjf12\AppData\Local\Temp\idea_junit.tmp
My Android studio command for running the unit test.
"D:\software\Android\Android Studio\jre\bin\java"
-ea
-Didea.test.cyclic.buffer.size=1048576
-Didea.launcher.port=3647
"-Didea.launcher.bin.path=D:\software\Android\Android Studio\bin"
-Dfile.encoding=UTF-8
-classpath
"D:\software\Android\Android Studio\lib\idea_rt.jar;
D:\software\Android\Android Studio\plugins\junit\lib\junit-rt.jar;
D:\software\Android\Android Studio\plugins\junit\lib\junit5-rt.jar;
D:\software\Android\sdk\platforms\android-27\data\res;
D:\code\android\myProjectAndroid\myprojectandroid\build\intermediates\classes\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\tmp\kotlin-classes\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\generated\res\rs\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\generated\res\resValues\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\intermediates\unitTestConfig\test\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\tmp\kotlin-classes\debugUnitTest;
D:\code\android\myProjectAndroid\myprojectandroid\build\tmp\kotlin-classes\debugAndroidTest;
D:\code\android\myProjectAndroid\myprojectandroid\build\generated\res\rs\androidTest\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\generated\res\resValues\androidTest\debug;
D:\software\Android\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy-agent\1.7.9\a6c65f9da7f467ee1f02ff2841ffd3155aee2fc9\byte-buddy-agent-1.7.9.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.objenesis\objenesis\2.6\639033469776fd37c08358c6b92a4761feb2af4b\objenesis-2.6.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.0\edf3f7bfb84a7521d0599efa3b0113a0ee90f85\common-1.1.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\27.1.1\39ded76b5e1ce1c5b2688e1d25cdc20ecee32007\support-annotations-27.1.1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-27.1.1.aar\87b44b5092008154f1171a969696f102\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\5e64a504ec19504fa9b2687a61b079c4\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-compat-27.1.1.aar\5e64a504ec19504fa9b2687a61b079c4\res;
D:\software\Android\.gradle\caches\modules-2\files-2.1\net.bytebuddy\byte-buddy\1.7.9\51218a01a882c04d0aba8c028179cce488bbcb58\byte-buddy-1.7.9.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.0.aar\8d37b7feb2744759cd91b03ad94efb30\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.mockito\mockito-core\2.15.0\b84bfbbc29cd22c9529409627af6ea2897f4fa85\mockito-core-2.15.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.nhaarman\mockito-kotlin\1.5.0\25faa884f76375f76cdbd6651c4cebcde36d4117\mockito-kotlin-1.5.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\com.github.kotlin-graphics\kotlin-unsigned\v2.1\52408e5d299c5d1fb669188dae56fa5bb37cbc12\kotlin-unsigned-v2.1.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-27.1.1.aar\8949c790c8f1bf421289f293aa4e1cc2\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\1c49103dd8f3bd81aa06fd4de90258d6\jars\classes.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\1c49103dd8f3bd81aa06fd4de90258d6\res;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-core-utils-27.1.1.aar\fb3bae07f3360874234d36f26caa5ebb\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\support-fragment-27.1.1.aar\0464588052e7fe27a8be9d866a5cd81f\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\4aa45f99c024430a3ccf7c0e257fb60a\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\2668a362e92dc09e5e5a2ec0e09458ea\res;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\2668a362e92dc09e5e5a2ec0e09458ea\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.2.30\9758025a415ee400e1f90ff222bcfec247779133\kotlin-reflect-1.2.30.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.2.30\2dfac33f8b4e92c9dd1422cd286834701a6f6d6\kotlin-stdlib-1.2.30.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.0.aar\8c471aa13e8c6e412a4748be6e503cbc\jars\classes.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.0\8007981f7d7540d89cd18471b8e5dcd2b4f99167\common-1.1.0.jar;
D:\software\Android\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.2.30\ca12c47fc1e3a7316067b2a51e2f214745ebf8c5\kotlin-stdlib-jdk7-1.2.30.jar;
D:\software\Android\.gradle\caches\transforms-1\files-1.1\runtime-1.1.0.aar\f827adbdf97ad86b4140dcb5e1073a50\jars\classes.jar;
D:\code\android\myProjectAndroid\myprojectandroid\build\intermediates\sourceFolderJavaResources\test\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\intermediates\sourceFolderJavaResources\debug;
D:\code\android\myProjectAndroid\myprojectandroid\build\generated\mockable-android-27.default-values.v3.jar"
com.intellij.rt.execution.application.AppMainV2
com.intellij.rt.execution.junit.JUnitStarter
-ideVersion5
#w#C:\Users\cjf12\AppData\Local\Temp\idea_working_dirs_junit.tmp
#C:\Users\cjf12\AppData\Local\Temp\idea_junit.tmp
-socket3646
This is my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "org.mycompany.myproject"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/java'
test.java.srcDirs += 'src/test/java'
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.github.kotlin-graphics:kotlin-unsigned:v2.1'
// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:2.15.0'
testImplementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation "com.nhaarman:mockito-kotlin:1.5.0"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation 'com.github.kotlin-graphics:kotlin-unsigned:v2.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
1- Add this to your build.gradle
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
testImplementation "org.powermock:powermock-api-mockito:${powerMockVersion}"
Checkout the supported versions of Mockito and PowerMock
For example if you use v1.9.5 for Mockito use v1.6.6 for PowerMock
2- Annotate your test class with this
#RunWith(PowerMockRunner.class)
#PrepareForTesting(Log.class)
public class YourTestClass {
And your test cases should run now.
Also as #Code-Apprentice said if you want to log something inside the testing class use System.out.println(). Do not use Android dependencies for testing, this just to bypass the logs inside the methods you are unit testing.
UPDATE
Adding this to your build.gradle will also help with no need for PowerMock (not highly recommend). Please refer to this answer
android {
//...
testOptions {
unitTests.returnDefaultValues = true
}
}
When running unit tests, no methods from the Android API are available. The error "java.lang.RuntimeException: Stub!" occurs when you try to call any of these functions, including Log.e(). If you need output, use the standard System.out.println() instead. Or use the IntelliJ debugger.
Related
I'm writing an android plugin for unity to be able to check if notifications are enabled for the game. I have one java class with a method for checking if notifications are enabled. When i build the plugin and then the .apk with unity everything works fine. But after installation, when calling the mehthod i get the following exception:
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationManagerCompat;
The Java class
package com.example.plugin;
import android.app.Activity;
import androidx.core.app.NotificationManagerCompat;
public class NotificationPlugin {
public static boolean areNotificationEnabled(Activity unityActivity) {
return NotificationManagerCompat.from(unityActivity).areNotificationsEnabled();
}
}
buld.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
gradle.properties
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
Haven't found a solution anywhere else yet. Thank in advance. It's probably a super simple fix that i miss.
Update
Custom gradle.properties in unity set with android.enableJetifier and android.useAndroidX set to true
Jetifier was enabled in unity
Androidx.Core libary was added to the dependencies of the gradle.build file of the plugin
None of the above solved the issue
Solution
As Hamid Yusifli suggested in his answer a custom gradle build template needs to be enabled (Project Settings>Player>Publishing Settings>Custom Main Gralde Template) and the dependencies for the libary need to be added (implementation 'androidx.core:core:1.5.0' in my case). This solved the issue.
So, seems like in your case unity ignores your library gradle dependencies,
there are many different reasons why this could happen. To force unity to include missing dependencies you must provide a custom Gradle build template and add your dependencies in that file.
I am trying to develop an SFTP client using sshj on Android studio such that the App can connect securely to the server using SFTP over ssh. The code was running fine, but when I added the "sshj-0.10.0" module, it gives me this complicated error.
The "sshj-0.10.0" module is needed to run server code using net library as below:
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
I added the module the project and configured it in the dependencies in build.gradel of the app as shown below:
What I have tried so far (but not limited to):
1- Clean Project then Rebuild Project - failed
2- Invalidate Caches / Restart - failed
3- Delete .gradle and .idea from my root project- failed
4- Added
android {
defaultConfig {
multiDexEnabled true
}
}
and
dependencies {// Multidex
implementation 'com.android.support:multidex:1.0.3'
implementation project(path: ':sshj-0.10.0')
}
No solution was worked with me.
Here is my build.gradle(:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mohsenali.autosen"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//TedPermission
implementation 'gun0912.ted:tedpermission:1.0.3'
implementation files('D:/SKKU_PhD/Android/workspace_2018_projects/AutoSen/app/libs/commons-net-3.7.1.jar')
// Multidex
implementation 'com.android.support:multidex:1.0.3'
implementation project(path: ':sshj-0.10.0')
}
I know that this kind of error is popular but I tried many possible solutions available on SO since two days ago but none of them has helped me. So please don't mark it duplicated, maybe someone could help. Thanks.
Finally, I solved this error bu creating "libs" folder in the root of "app" project, and added the .jar library to it. After that I updated the code in "build.gradle(:app)" by adding this line: "implementation files('path to/app/libs/jsch-0.1.55.jar')".
I've been working with Firebase Database.The code was working fine for Firebase Authentication but showed this error message when added Firebase Database.
Incorrect value for field 'Signature': value is 662655099 but 67324752 expected.
Following is the gradle script:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.sudhanshujaisani.mywhatsapp"
minSdkVersion 21
targetSdkVersion 27
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(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
}
Thanks in advance.
I don't really know what causes this error but I had it too and I figured out (after some research) that it's something going on with Instant Run. It hasn't got anything to do with firebase, but I think it's something about Gradle and importing packages.
Anyway, I figured disabling Instant Run as a simple workaround and it worked! :)
In Android Studio:
File -> Settings (or press Ctrl+Alt+S).
Build, Execution, Deployment -> Instant Run (on the left panel).
Uncheck the first checkbox "Enable Instant Run to hot swap code/resource changes on deploy (default enabled)".
If you actually need Instant Run, this workaround won't help. I'm still trying to find the actual solution.
Invalidate Cache & Restart didn't work for me.
Try,
Build -> Clean Project
Build -> Rebuild project
File -> Invalidate Caches/Restart -
Update your android sdk, partial installations cause this problem.
I wanted to run the following test:
package com.xxx.yyy;
import android.content.Context;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* #see Testing documentation
*/
#RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
#Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.xxx.yyy", appContext.getPackageName());
}
}
But I get the error in the console:
$ adb shell am instrument -w -r -e debug false -e class 'com.xxx.yyy.ExampleInstrumentedTest' com.xxx.yyy.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Test running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.
I can not figgure out why its not working.
Here is my gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'org.greenrobot.greendao' // das kann dann später weg
//apply plugin: 'kotlin-kapt' // if using Kotlin
//apply plugin: 'io.objectbox'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 21
targetSdkVersion 28
versionCode 130
versionName "1.3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
greendao {
schemaVersion 4
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'org.greenrobot:greendao:3.2.2'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-ads:15.0.1'
testImplementation 'junit:junit:4.12'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
Any suggestions?
Found the solution by myself.
I updated to AndroidX, therefor I needed also to update my build.gradle file from:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
to
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
I got the error:
Test running failed: Instrumentation run failed due to 'Process crashed.'
In my case, the android test console only showed the error above without any details.
But in the logcat, the full error was shown. In my case, I forgot to add the AdMob app_id in AndroidManifest.xml
So always remember to check the logcat for more error details!
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "androidx.test:core:1.3.0"
androidTestImplementation "androidx.test.ext:junit:1.1.2"
androidTestImplementation "androidx.test:rules:1.3.0"
except for the androidx.test.runner.AndroidJunitRunner config, please also check the dependency. The above code is worked for me.
So I had the same symptoms but after making all these changes I found that the following config in my project build.gradle file that was an issue
buildTypes{
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
seems that minifyEnable and shrinkResources are behaving differently after the upgrade to androidx, could have happened earlier but I just realized it now. Commenting out the lines fixed my No Tests Found Issues.
buildTypes{
debug {
debuggable true
//minifyEnabled true
//shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
I got the same error after updating JUnit4 from:
androidTestImplementation 'junit:junit:4.12
to
androidTestImplementation 'junit:junit:4.13
The error went away when I downgraded back to:
androidTestImplementation 'junit:junit:4.12
Generally you'd want the whole suite to match at once: https://developer.android.com/jetpack/androidx/releases/test
So for example, the latest as of writing is
Core 1.4.0
Espresso 3.4.0
Intents 3.4.0
JUnit 1.1.3
Monitor 1.4.0
Orchestrator 1.4.0
Runner 1.4.0
Rules 1.4.0
Truth 1.4.0
Test Services 1.4.0
This error appeared because I changed testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" to testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit4" in build.gradle. In LogCat I saw:
java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.example.debug.test/androidx.test.ext.junit.runners.AndroidJUnit4}: java.lang.ClassNotFoundException: Didn't find class "androidx.test.ext.junit.runners.AndroidJUnit4" on path: DexPathList[[zip file ...
For me, I was working with runtime permission and revoking the permission (tried adb commands and uiAutomation.revokeRuntimePermission) caused this issue, as an alternate approach, I used Android Test Orchestrator, that seems to be working great so far.
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.