Run Robolectric tests from IDEA - android

I'm trying to run
RobolectricSample
RobolectricDemoProject
project with IDEA and i got error
Class not found: "de.peterfriese.robolectricdemo.MainActivityTest"
Process finished with exit code 1
but when i use gradle test command all is ok.
this is my Junit config

now, in IDEA you have using non gradle project. That mean you can look on project structure (Ctrl+Shift+Alt+S) and look on Library visibility. (Runtime, Provided,etc) also export property are exist. When library are provided or no exported, it will be absent in target apk.
Also you can build project as gradle test project. so IDEA will use your gradle test target. Build will take litle more time.

Related

Android Room + Kotlin + Kapt + IntelliJ + MacOS Catalina: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8

Using Android Room with Kapt on MacOS Catalina, I get the following errors building the project. The project builds successfully if I remove kapt "androidx.room:room-compiler:$room_version" from my build.gradle.
Failed to load native library:sqlite-3.25.2-60e239c7-424b-4b75-bfd5-b2df4aa8e01a-libsqlitejdbc.jnilib. osinfo: Mac/x86_64
java.lang.UnsatisfiedLinkError: $TMPDIR/sqlite-3.25.2-60e239c7-424b-4b75-bfd5-b2df4aa8e01a-libsqlitejdbc.jnilib: dlopen($TMPDIR/sqlite-3.25.2-60e239c7-424b-4b75-bfd5-b2df4aa8e01a-libsqlitejdbc.jnilib, 1): no suitable image found. Did find:
$TMPDIR/sqlite-3.25.2-60e239c7-424b-4b75-bfd5-b2df4aa8e01a-libsqlitejdbc.jnilib: code signature in ($TMPDIR/sqlite-3.25.2-60e239c7-424b-4b75-bfd5-b2df4aa8e01a-libsqlitejdbc.jnilib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
Failed to load native library:sqlite-3.25.2-79b61bc4-bdd0-4451-a523-5baa49728398-libsqlitejdbc.jnilib. osinfo: Mac/x86_64
java.lang.UnsatisfiedLinkError: $TMPDIR/sqlite-3.25.2-79b61bc4-bdd0-4451-a523-5baa49728398-libsqlitejdbc.jnilib: dlopen($TMPDIR/sqlite-3.25.2-79b61bc4-bdd0-4451-a523-5baa49728398-libsqlitejdbc.jnilib, 1): no suitable image found. Did find:
$TMPDIR/sqlite-3.25.2-79b61bc4-bdd0-4451-a523-5baa49728398-libsqlitejdbc.jnilib: code signature in ($TMPDIR/sqlite-3.25.2-79b61bc4-bdd0-4451-a523-5baa49728398-libsqlitejdbc.jnilib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
Which produces the following exception
Caused by: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V
at org.sqlite.core.NativeDB._open_utf8(Native Method)
at org.sqlite.core.NativeDB._open(NativeDB.java:78)
at org.sqlite.core.DB.open(DB.java:195)
at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:243)
at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:61)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:21)
at org.sqlite.JDBC.createConnection(JDBC.java:116)
at androidx.room.verifier.DatabaseVerifier$Companion.create(DatabaseVerifier.kt:104)
at androidx.room.processor.DatabaseProcessor.doProcess(DatabaseProcessor.kt:82)
at androidx.room.processor.DatabaseProcessor.process(DatabaseProcessor.kt:57)
at androidx.room.RoomProcessor$DatabaseProcessingStep.process(RoomProcessor.kt:134)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:985)
... 39 more
It looks like this is different from https://github.com/xerial/sqlite-jdbc/issues/97, which is the only issue I could find any information about. Is there any way to work around this issue?
Edit:
I ended up finding this blog post, which led me to this JDK issue. I verified that ./gradlew :app:kaptDebugKotlin worked with my JDK11, and updated IDEA to use that JDK as it's runtime, as well as telling it to execute builds with gradle instead of IDEA. Neither of those seemed to fix the issue - running ./gradlew clean :app:kaptDebugKotlin in my terminal with JDK11 succeeded, but running that gradle task through IDEA failed.
I ended up working around it by removing gradle-aware make from my run configuration, and running ./gradlew :app:assembleDebug every time I make changes to the app. It's a little annoying and adds an extra step, but I can still run/update the app.
Figured it out - it turns out the Gradle setting for Java SDK is ignored in Android projects, and instead the Java SDK from the Android SDK is used for gradle tasks. Setting the Android SDK's Java SDK to JDK11 fixed the issue, because that JDK has the fix for JDK-8223671

No Tests Found Android Studio 3.2

Right clicking on a package and selecting Run Tests... results in the message No tests were found. In earlier versions of Android Studio my tests were found and would run using this method. Running test classes individually seems to work still. I've tried Invalidate Cache / Restart, but still running into the same issue.
Logs:
---- IntelliJ IDEA coverage runner ----
sampling ...
include patterns:
exclude patterns:0 test classes found in package '<default package>'
Process finished with exit code 254
Empty test suite.
Any point in the right direction would be appreciated. Thanks!
I've seen this happen when AS tries to run unit tests (test/ folder) instead of instrumentation tests (androidTest/ folder) or the package specification for the configuration is wrong.
Make sure that when you right click a folder to run the package of tests, and select "Run", that the icon has a little droid on it to indicate it's treating the folder as android tests:
If it doesn't, continue to step 2. If it does, skip to step 3.
Sometimes AS gets confused and thinks Android tests are unit tests. To fix that, click the Run Configuration icon in the toolbar and select "Edit Configurations..."
You should see an option for Android Tests:
Select this and copy that configuration, then on the right, change it from "All in Module" to "All in Package"
Make sure the configuration for the package tests specifies the full package you want to test:
Once your configuration is correctly set up to run Android tests and explicitly indicate the full and correct package of tests to run, it should work.
Hope that helps!
Fixed in Android Studio version 3.2.1
Invalidate caches and restart fixed this for me, always worth trying.
If you are using JUnit 5 and already have JUnit 4 synced in your build.gradle then make sure that #Test annotation should be annotated from import org.junit.jupiter.api.Test
This is classic. Some of these steps might help:
Kill Gradle daemons: ./gradlew --stop
Reimport the project: close the Android Studio window, delete the project from the list of recent projects, Import again.
Report it to the Tools team: https://developer.android.com/studio/report-bugs
In my case I inadvertently had both JUnit4 and JUnit5 on the classpath.
Even though I was trying to use JUnit5 in my tests, one of my test dependencies had a transitive dependency on the older version.
After cleaning up the classpath Android Studio (3.2.1) was able to find the tests again.

Gradle Build : error package does not exist

I was developing an android app (using Eclipse, not Studio) following some example, which makes use of Github/CircleImageView. Hence, I wanted to compile that first into a jar library.
So on my Linux machine I installed gradle and since its my first time with gradle, I followed the tutorial on gradle. So, in the root directory of the project ~/Downloads/CircleImageView-master/, I :
Run gradle wrapper. Got Build Success
Run ./gradlew build, gives the following error
CircleImageView.java:21: error: package com.nineoldandroids.animation does not exist
import com.nineoldandroids.animation.ObjectAnimator;
Though, I can see that there is one jar file in the project ~/Downloads/CircleImageView-master/circleimageview/libs/nineoldandroid-library-2.4.0.jar. Can anyone please help in resolving the issue. I am trying since past 10 hours and reached so far here after resolving all the issues, and stuck just at the last point.
I opened the jar in a package manager and the required classes are there, including ObjectAnimator.

Eclipse gradle plugin works, but library classes are not recognized

After days and days of hard work, I have my android project without errors in Eclipse.
I used build.gradle. Now, I can add library in that file writing "compile 'com.somelib.version'.
Now, I can type 'gradle clean' and 'gradle build'. These commands don't show errors. So, I think project added dependencies correctly. But I add Gson, or different library with gradle, how can I use it?
Eclipse give eror if I type 'import com.google.gson' (in this example). So, maybe I forgot a step before having dependencies working?
You may want to run these gradle commands:
cleanEclipseClasspath
eclipseClasspath
This worked for me when I had your issue.

Errors running builder 'CDT Builder' when trying to build OpenCV for android samples

Hello guys I'm trying to learn about openCV in android
I've already following the instruction given here
but when I'm trying to compile I'm only getting
01:50:14 ** Auto Build of configuration Default for project
org.opencv.samples.fd.FdActivity **
"C:\Android\android-ndk-r8\ndk-build.cmd" Install:
libdetection_based_tracker.so =>
libs/armeabi-v7a/libdetection_based_tracker.so
01:50:14 Build Finished (took 184ms)
in the console
and I'm also get an error
Errors occurred during the build. Errors running builder 'CDT Builder'
on project 'org.opencv.samples.fd.FdActivity'. Internal error building
project org.opencv.samples.fd.FdActivity configuration Default
java.lang.NullPointerException Internal error building project
org.opencv.samples.fd.FdActivity configuration Default
java.lang.NullPointerException
anyone ever encountered this problem before?
please help me to solve this problem
thank you
try
Project Properties>C/C++ Build>Tool Chain Editor
Current toolchain: Android GCC
Current builder: Android Builder
Project Properties>C/C++ Build
(uncheck) use default build command
Build command: ndk-build
(uncheck) generate Makefiles automatically
You may have renamed the project, and the eclipse forgot to rename the "Refresh Policy".
Just update "Project properties -> C/C++ Build -> Refresh Policy" manually solved my problem.
BTW, ADT has some very bad error descriptions as of in this case.
I might have the same problem,
try ndk-build -B which rebuild all the things, see whether you still got error,
if no error remain, there is no problem with your ndk-build. try to run your android apps without CDT installed, if this works, at least we could use comand line to build the c++ part of code.
but CDT is still not working well, after I install the CDT according to the opencv doc, I got lots of errors, add the cygwin and gcc things to the path would solved most of it. But the last things every strange is, I got an error here.
in the face detection sample, .cpp part
catch(cv::Exception e)
{
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
it always says symbol "e" can not be resolved.
but no error when I include the opencv things.
even when I try to put cv::Exception e outside of the catch()
These works for me:
Build command: ndk-build
(uncheck) generate Makefiles automatically

Categories

Resources