I have been trying to add ReactNative to my existing android application. I followed the instructions from this link. I could add it but the app gets crashed once I open the react native activity. I have started server using
adb reverse tcp:8081 tcp:8081
and started react-native using
react-native start
I get a dialogue that the js files are loading. But finally end up with a crash. Following is the error that is being printed in logcat:
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libreactnativejni.so
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:213)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:178)
at com.facebook.react.bridge.JSCJavaScriptExecutor.<clinit>(JSCJavaScriptExecutor.java:19)
at com.facebook.react.ReactInstanceManager.onJSBundleLoadedFromServer(ReactInstanceManager.java:413)
at com.facebook.react.ReactInstanceManager.createReactContextInBackground(ReactInstanceManager.java:236)
I am completely lost as I am unable to figure out the cause for this issue.
Thanks in advance.
actually in my case these steps worked:
uninstall the app from the device
close Metro Bundler
run ./gradlew clean on android directory
run react-native run-android
hope to help you.
This has fixed my issue :
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
This should be placed build.gradle defaultConfig section.
This is caused by the following issue (open for 2 years) https://github.com/facebook/react-native/issues/2814
From the issue:
React Native on Android doesn't provide a 64-bit version of the libreactnativejni.so native library, which can cause compatibility issues on 64-bit devices. I ran into this while attempting to integrate React Native with a large existing application I'm developing.
Reaction from Facebook:
"Thanks for reporting! Yes we don't provide 64-bit version of the native code and the system should always fall back to 32-bit."
And:
"Most Android projects use a number of 3rd-party libraries, and any that include native 64-bit code will cause React Native to fail."
The following SO answer Use 32-bit jni libraries on 64-bit android explains fallback to 32-bit libraries and the fact you cannot mix. So if 64-bit is found, all should be 64-bit
I suggest reading along the Github issue #2814. There are multiple fixes proposed, but it depends on your situation what works.
The issuer has also written a blog about it: Mixing 32- and 64-bit Dependencies in Android
Hope this helps!
To me what worked was to clean project build and build it again.
Solution 1:
follow these steps:
uninstall the app from the device
close Metro Bundler
run ./gradlew clean on android directory
run react-native run-android
hope to help you.
Solution 2:
you can use the old version of soloader by adding configurations.all into your build.gradle
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
reference
https://stackoverflow.com/a/61695629/8079868
I solved this issue, update fresco library that is support for app bundle is 2.0.0 below this will not support,
Update: For me the issue got solved after updating fresco to 2.0.0, because 1.11.0 apparently didn't have support for Android App Bundles. I don't know if you all had the same problem, though.
just do this :
implementation 'com.facebook.fresco:fresco:2.0.0'
I had the same issue when running on Android 30. Following addition to the android/build.gradle file worked for me:
configurations.all {
resolutionStrategy {
// use 0.9.0 to fix crash on Android 11
force "com.facebook.soloader:soloader:0.9.0"
}
}
Credits
This worked for me,
cd android
./gradlew clean
It might be lib\x86_64\libreactnativejni.so not found due to missing strip tool for ABI 'X86_64'
Try the following steps.
Uninstall the apk
Clean the android folder
Navigate to android folder cd android.
Clean the directory using
gradle
For Windows, gradlew clean
For Linux, ./graldew clean
Now you can try react-native run-android --no-jetifier
Step 1: Goto Android Studio -> Build -> clean project.
Step 2: delete the project in your device.
Step 3: run react-native start.
Step 4: run npx react-native run-android.
It's working for me, no need of any gradle related changes.
if you are fresco libray then make sure use latest version and set the properties as false :
shrinkResources false
minifyEnabled false
Inside build.gradle file.
have an error in my application but I can not find it. Android 5.0 works normally, but in 4.4 of this error below:
Could not find class
'com.quickblox.q_municate.utils.ImageUtils$SmartUriDecoder',
referenced from method
com.quickblox.q_municate.utils.ImageUtils.getImageLoaderConfiguration
Shortly after it appears:
java.lang.NoClassDefFoundError:
com.quickblox.q_municate.utils.ImageUtils$SmartUriDecoder
at
com.quickblox.q_municate.utils.ImageUtils.getImageLoaderConfiguration(ImageUtils.java:67)
at com.quickblox.q_municate.App.initImageLoader(App.java:32)
at com.quickblox.q_municate.App.initApplication(App.java:42)
at com.quickblox.q_municate.App.onCreate(App.java:27)
Does anyone know what can it be?
You can try doing,
multiDexEnabled = false
in your build.gradle file.
If you already have multiDexEnabled = true then change it to false or add this new line.
Make sure that you have the correct libraries imported in your project and go to your gradle to make sure that you're compiling everything that you're trying to use.
I'm strugling with using jackson-dataformat-xml on android
I have some very basic code that works fine on oracle jre
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
First I tried official documentation adapted for gradle (by me, not sure if done correctly):
compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'javax.xml.stream:stax-api:1.0-2'
Result: gradle fails build time about bundling corelibraries into an application
...
:app:preDexDebug
trouble processing "javax/xml/stream/EventFilter.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
...
2nd attempt trying to follow Sean's answer
(Basicly he repackages corelibs with prefix names and rebuilds jackson-dataformat-xml to use the prefixed names)
compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'
// Repackaged XML-specific libraries
compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'
compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'
compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'
compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'
And build time failed on duplicates
Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec
so added:
packagingOptions {
...
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
When adding the exclusions it builds and deploys, but fails runtime on below stackdump (AFAIK it cant find the SAX provider, even tho it is added to the classpath to my understanding)
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:97)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:82)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:46)
What is the proper way to move forward on either #1 or #2?
Number 2 is the correct approach (Android doesn't like it when you include classes in the official Java package namespace - but then again, I wrote the original answer so I'm biased ;) ).
I believe the FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found error is due to a bug in the Android build tools. In previous versions of ADT for Eclipse and Gradle plugin < 0.7.0 the /META-INF/* files are stripped from the JARs during the build process. It seems like >= v0.7.0 shouldn't have the problem according to Google, but from others' reports it sounds like it still may be problematic, and could potentially remove the META-INF/services/javax.xml.stream.XMLInputFactory file, which is required for the platform to register Aalto.
Try the workaround mentioned in AOSP issue 59658 comment 22:
right click on /src/main (where you have /java and /res folders),
select New > Folder > Java Resources Folder,
click Finish (do not change Folder Location),
right click on new /resources folder,
select New > Directory
enter "META-INF" (without quotes),
right click on /resources/META-INF folder,
select New > Directory
enter "services" (without quotes)
copy any file you need into /resources/META-INF/services
For you, in step 10 above you'd need to copy this file into /resources/META-INF/services. In case the file link is broken in the future, the name of the file is javax.xml.stream.XMLInputFactory and it consists of a single line:
com.fasterxml.aalto.stax.InputFactoryImpl
EDIT
If you get a "Error:duplicate files during packaging of APK... Path in archive: META-INF/services/javax.xml.stream.XMLInputFactory", you can try telling Gradle to keep the first occurrence with:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.xml.stream.XMLInputFactory'
}
}
EDIT 2
This bug may be affecting "pickFirst". Please make sure you're running the latest version of Android Studio, and update your local tools and Android Gradle plugin to make sure you're running the most recent version of the tools. This may be fixed in Android Studio 1.3 RC1.
I have attempted to add XmlPull support to jackson xml. Find the forked project here:
https://github.com/finvu/jackson-dataformat-xml
Currently, only supported for version 2.9.6. (clone the branch jackson-dataformat-xml-2.9.6-XmlPull)
Sorry, I am not able to provide detailed documentation due to time constraints. If you have knowledge of git and maven to pull a specific branch and build the jar, then it should be relatively easy.
To those who will be in need of this in the future:
first integrate Jitpack in Your Android app, following their instructions:
https://jitpack.io/
Then paste teh GitHub url of jackson-dataformat-xml on Jitpack sites' corresponding text box. GitHub url is:
https://github.com/FasterXML/jackson-dataformat-xml.
That's it! Enjoy the result. :)
Receiving the following message when uploading my latest APK:
You need to use a different version code for your APK because you already have one with version code 1.
I am setting the android:versionCode and android:versionName correctly (in /app/src/main/AndroidManifest.xml):
android:versionCode="2"
android:versionName="1.1"
Also, I am using the same keystore that the project was initialized / originally built with
This is my 5th app and I've never encountered this issue before.
Is there some other place within a typical Android app project that could override the versionCode found in the AndroidManifest.xml file? Or maybe some kind of "de-linter" tool that'll help?
The path names suggest you're using Android Studio. Android Studio is using the Gradle build system. Possibly the build.gradle files specify version name/code that override whatever you set in manifest. So, to change it, edit your build.gradle file(s) and check for overridden versionCode / versionName.
Clean your app. Then save all files and then build
When I attempt to run the following test in IntelliJ IDEA I get the message:
"!!! JUnit version 3.8 or later expected:"
It should be noted that this is an Android project I am working on in IntelliJ IDEA 9.
public class GameScoreUtilTest {
#Test
public void testCalculateResults() throws Exception {
final Game game = new Game();
final Player player1 = new Player();
{
final PlayedHole playedHole = new PlayedHole();
playedHole.setScore(1);
game.getHoleScoreMap().put(player1, playedHole);
}
{
final PlayedHole playedHole = new PlayedHole();
playedHole.setScore(3);
game.getHoleScoreMap().put(player1, playedHole);
}
final GameResults gameResults = GameScoreUtil.calculateResults(game);
assertEquals(4, gameResults.getScore());
}
}
The full stack trace looks like this...
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:152)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:136)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Process finished with exit code -3
This problem happens because Android Platform (android.jar) already contains JUnit classes. IDEA test runner loads these classes and sees that they are from the old JUnit, while you are trying to use annotated tests which is a feature of the new JUnit, therefore you get the error from the test runner.
The solution is simple, open the Project Structure | Modules | Dependencies, and move the junit-4.7.jar up, so that it comes before Android 1.6 Platform in the classpath. Now the test runner will be happy as it loads the new JUnit version.
my module is a java library module, so changing JRE to 1.8 java solved the issue.
Or, you can also do it globally via Module Settings > SDK Location > JDK, specifying Oracle's JDK 8 instead of Android SDK's copy.
I had this problem with a multi module project (libgdx). One module is pure Java and has tests.
My solution was to set "use alternative JRE" to "Java 1.8" in the run configuration of my unit tests. This makes sure no android.jar is on the classpath and the junit 4.x runner is used.
I got the same error when creating both Unit Test and Android Instrument Test in Android Studio 1.4+ and it started to get confused. To avoid this error make sure your test class is fall under Android Tests on Run/Debug Configurations
Make sure you follow the instruction properly https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
Make sure Test Artifact in Build Variants is set to Android Instrumentation Tests
Click menu Run > Edit Configuration
Make sure your class/method name is inside Android Tests instead of JUnit
If it is in JUnit simply delete the config and right click on the file you want to test and Run again. It will then create the config under Android Tests section and it run on device/emulator.
For Android Studio - starting from Android Studio 1.1 Beta 4, Google has added support for Android Gradle plugin 1.1.0-RC. The new plugin supports Unit Testing through Android Studio using junit 4+.
This is still experimental and there are some manual steps to set this up.
For everyone who is reading this post and still have the same issue with AndroidStudio 1.0. You cannot change the dependency order in AndroidStudio has the IDE re-write them automatically. And, even if you manage to change the order by modifying the .iml file, you will get a "class not found...". This is because the Test output path cannot be set on AndroidStudio.
Actually, there is solution to make AndroidStudio, Junit and Robolectric working together. Take a look at this https://github.com/JCAndKSolutions/android-unit-test and use this plugin as well : https://github.com/evant/android-studio-unit-test-plugin
Works perfectly for me.
For me this problem was caused by an outdated/broken run configuration for the tests. I simply had to delete the configuration, then create a new one and the problem was fixed.
I have got the same error when i have create my own junit package
To fix this, i have added these two lines in my app gradle file as it's explained here :
dependencies {
...
// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
}
I got the same message
JUnit version 3.8 or later expected
by a simple beginner's mistake. I had used the same package names and class names on src/main and src/test for a class (the HomeController class in my case):
my-test-project
+--pom.xml
+--src
+--main
+--com
+--example
+--Application.java
+--controller
+--HomeController.java
+--test
+--com
+--example
+--ApplicationTest.java
+--controller
+--HomeController.java <---- same package and class name: not good!
With that, the src/main HomeController class, as well as the src/test HomeController class, had the same full path:
com.example.controller.HomeController.class
The result: any tests that were dependent on the HomeController class have failed.
Either changing the package name and/or the class name has resolved the issue. Here the example, when both, the package name and the class name is changed:
my-test-project
+--pom.xml
+--src
+--main
+--com
+--example
+--Application.java
+--controller
+--HomeController.java
+--test
+--com
+--example
+--test <---- added (optional)
+--ApplicationTest.java
+--controller
+--HomeControllerTest.java <---- changed
Now the fully qualified class names differ. The src/main HomeController class name is:
com.example.controller.HomeController.class
and the src/test HomeHontrollerTest class name is:
com.example.test.controller.HomeControllerTest.class
With the fully qualified class names being unique, the problem disappears.
There are two thing I could imagine to happen
If your IDE tries to start an Android
Junit test that directly runs on the
emulator you can't use Junit4.
If you accidentally used the junit classes provided from the android jar they can't run on a normal jvm because there are only real compiled classes for the android dalvik vm.
This happened to me as well in Android Studio 1.1 - although it should support unit tests without a plugin.
On other machines (same project, same version of AS) I found that when running unit tests, the IDE does not add the android.jar file to the classpath, while in my machine it does.
My best guess was that due to the conversion we did from Maven to Gradle and moving from intellij to AS some cache of settings remained somewhere in my machine that caused android.jar to be added to the classpath.
What I did is to clear all android related caches from my machine (under the c:\users\USRE_NAME folder):
.android
.AndroidStudio
.gradle
.m2
After that I reopened the project and the tests worked.
Still trying to understand what went wrong, but this should do the trick for now.
I had this issue in Android Studio 1.5, because I did not know that I had to switch the "Test Artifact" setting in the "Build Variants" (lower left corner of the main window) from "Android Instrumentation Tests" to "Unit Tests". When you do, you can see an ExampleUnitTest.java file in the Project window.
I had the same problem but for another reason. I was on IntelliJ with a regular java gradle project (not android) but the JDK was set to the Android SDK in Project Structure (was the default JDK for some reasons). This is really dumb but IntelliJ wasn't nice enough to indicate me what's wrong, so I got stuck on that.
This is how I solved it:
Edit Configurations -> Defaults -> Android JUnit -> Add the following to Working Directory:
$MODULE_DIR$
Worked when I update IDEA version to 2021.2.1.
In Android project I had minifyEnabled = true, after I changed it to false everything worked.
If you remove
testOptions {
unitTests.returnDefaultValues = true
}
from your build.gradle it will work
Go to Project Structure -> Platform Setting, change SDKs to 1.8
solved my problem.
I followed CrazyCoder's answer but there was no junit file shown in dependencies. so i downloaded one from http://www.java2s.com/Code/Jar/j/Downloadjunitjar.htm, then added it by pressing the plus button on the right. And it worked
Turning off "Use embedded JDK" in Project Structure/SDK Location is what helped in my case but I don't know exactly what was the reason it was failing in the first place.
Replace your android.jar in libs folder with the latest one.
You can download it from here
In AndroidStudio, Open Project Structure -> SDK Location, you can see JDK location, change use "Use embedded JDK" to you own JDK to apply, then change back to "Use embedded JDK", it's maybe work
In my case, change JRE in Run Configurations dose solve the problem, but when I click the run button next to the test function, the JRE options will reset to default.
Finally, similar to #CrazyLiu 's answer, in Project Structure - SDK Location - JDK, select Embedded JDK. Because there is no checkbox in Android Studio 3.6.
None of the above worked for me (Intellij 2019.3.5
Build #IU-193.7288.26), finally using 're-import all projects' button on the maven pane worked.
For me, i did delete useLibrary 'android.test.runner' line in android {} block at bulid.gradle module file and everything worked fine.
I had the same problem in a Java 11 with Spring project, turns out when I tried to run the test, I put the wrong "shorten command" option.
Using the "JAR Manifest" option fixed the issue.
IntelliJ shorten command options
I was also facing the same issue, after changing into build.gradle it's working fine for me.
change your junit version inside build.gradle to:
testImplementation 'junit:junit:3.8'