I'm running into number of problems while trying to run GStreamer Android Tutorials on Windows. I'am new to Android NDK so this could be a really simple issue but I couldn't figure out how to solve it.
These are the build error messages when I try to build the project
Build command failed.
Error while executing process
D:\gstreamer\android-ndk-r19b-windows-x86_64\android-ndk-r19b\ndk-build.cmd
with arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Android.mk
NDK_APPLICATION_MK=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Application.mk
APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0
APP_PLATFORM=android-16
NDK_OUT=C:/xxx/xxx/gst-docs-master/examples/tutorials/android/android-tutorial-1/build/intermediates/ndkBuild/release/obj
NDK_LIBS_OUT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\build\intermediates\ndkBuild\release\lib
NDK_APPLICATION_MK=jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src
GSTREAMER_ROOT_ANDROID=D:/gstreamer/gstreamer-1.0-android-universal-1.15.1
GSTREAMER_ASSETS_DIR=src/assets APP_SHORT_COMMANDS=false
LOCAL_SHORT_COMMANDS=false -B -n}
process_begin: CreateProcess(NULL, "", ...) failed.
*** Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
When I clicked the "Open File" it has sent me to gstreamer-1.0.mk file and the lines below.
ifdef SYSROOT
SYSROOT_GST_INC := $(SYSROOT)
SYSROOT_GST_LINK := $(SYSROOT)
else
ifdef SYSROOT_INC
$(call assert-defined, SYSROOT_LINK)
ifdef SYSROOT_LINK
SYSROOT_GST_INC := $(SYSROOT_INC)
SYSROOT_GST_LINK := $(SYSROOT_LINK)
endif
else
SYSROOT_GST_INC := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)
SYSROOT_GST_LINK := $(SYSROOT_GST_INC)
endif endif
I think the problem is about SYS_ROOT as mentioned in the error message but I don't know what "SYS_ROOT" means or "NDK_PROJECT_PATH" is.
I have added gstAndroidRoot to gradle.properties so while building this won't be a problem.
For Windows 10, Android Studio 3.5. This worked for me.
Download the entire gstreamer android studio tutorial directory from here.
Open Android Studio -> Open an existing Android Studio Project
Open the entire android tutorial directory examples/tutorials/android as a project
Once the project is open change the view on the left side of the screen to Project
Right click near local.properties. Right click -> file -> New -> File
Create a new file called gradle.properties
In the new gradle.properties file copy and paste the below code.
# gstAndroidRoot can be set to point to the unpacked GStreamer android top-level directory
# containing each architecture in subdirectories, or else set the GSTREAMER_ROOT_ANDROID
# environment variable to that location
gstAndroidRoot=/gstreamer_android_binaries
Note: Change the gstAndroidRoot variable to your file path where you downloaded the gstreamer binaries and unzipped them. Gstreamer can be downloaded from here for Android.
Now we need to set up NDK directory. Make sure you download and have NDK enabled under SDK tools.
This will download the latest NDK version. However gstreamer currently will not build with the latest NDK. We need to download NDK Revision 18b from here. If you do not use NDK version 18 you will likely get an error Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
Unzip the downloaded NDK 18b directory.
Take the unzipped android-ndk-r18b directory and move it to where the ndk folder is under AppData\Local\Android\Sdk\ndk
You should now have two folders within Android\Sdk\ndk. 20.0.5594570 (or latest version) and android-ndk-r18b
In android studio go to File -> project Structure
Under Android NDK location point to the NDK 18 directory. Example: C:\Users\AppData\Local\Android\Sdk\ndk\android-ndk-r18b
Connect a phone with USB debugging and run!
If you get an error on the phone stating it is for an older version of android. Go back to Android Studio and switch to Android View on the left side of the screen. Under Gradle Scripts select the build.gradle for the appropriate tutorial. Change the compileSdkVersion 29, minSDKVersion 15, and targetSDKVersion 29.
so I have my Xamarin.Android project which contains several libraries. When I try to build I receive an error which says "java.exe" exited with code 2.
After some hours of google research I found out that I could enable Multidex.
According to the blog entry of Jon Doublas I did the steps mentioned.
http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/
According to the blog entry Android API Level > 21 handles Multidex itself.
Well my experience is that it does not. I am building on API Level 25 and get the same error again and again with the same information.
The steps in the article do not help. It seems like Xamarin.Android does not support Multidex.
It seems like you have to handle Multidex by yourself but I haven't found any solution which is working. Dos anybody found a solution which works?
I am using Xamarin 4.6 and Visual studio 2017.
Found the answer after about 20 hours of searching in my project..
So here are the steps to resolve the problem "java.exe" exited with code 2
1) Change the MainDexClasses.bat as described in the link:
http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/
2) Make sure you have enabled Multidex Option in your Android Application! Have a look at the .csprj file if Multidex is set to true (in my case it wasn't even if I enabled Multidex)
3) Add the following part in your AndroidManifest file
<application android:name="android.support.multidex.MultiDexApplication"></application>
This will tell your Android project to actually use the Multidex-Option given.
After a clean and build I was able to run my application as it is.
After finding this question and #Daniel_97s answer I was able to solve this error only by adding multidex to the project without changing MainDexClasses.bat:
Check the option in Project Options:
Add MultiDexApplication to Android Manifest:
<application android:name="android.support.multidex.MultiDexApplication"></application>
Note I was getting this error code 2 on Visual Studio for Mac and on Windows the same app was building successfully. (why?)
The solution in my case was to disable the "Sign the .APK file using the following keystore details". Because the keystore location and/or password was incorrect, java.exe exited with code 2.
I only go to option > Build > Android Build and check Enable Multi-Dex it will resolve
My .csproj file had an entry for the KeyStore that was no longer valid, even thought right-clicking the project and inspecting the properties indicated that I had pointed it to the new location.
Within .csproj look for all instances of <AndroidSigningKeyStore> and update accordingly.
I've struggled with this issue for quite a long time. I found source of the error in signing - as I cloned project repo from company TFS, Android csproj file had entries for KeyStore settings and location. I didn't have the keystore and the location on my drive was invalid. Visual Studio is then unable to sign the app while deploying and instead of some sort of FileNotFoundException it gave me just java exited with code 2. So...
tl;dr: Go to android project properties, select package signing a uncheck "Sign the apk file..." (which changes csproj <AndroidKeyStore>true</AndroidKeyStore> to false) and voila, you can now run your solution.
Reassign the path of the keystore worked for me
==EDIT 01==
Double click on Android Project > Android Package Signing
On the Keystore path, don't know why but apparently the path was wrong, I re-select the .keystore file again from the same path, and the error "exited with code 2" went away and I was able to Archive for release
Disable sign the .APK file using the following keystore details as #Klemikaze
I had this error when switching from VS Mac to VS Windows.
Here the topic Switching From VS Mac To VS Windows got “java.exe” exited with code 2
The issue was comming from the Android.csproj and the Keystore Path.
It was set to my Mac Path even if I changed it on
VSWindows AndroidProject => Properties => Signin
So I removed this lines on Android.csproj (edited with third text editor):
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>YourMacPath/Alias.keystore</AndroidSigningKeyStore>
<AndroidSigningStorePass>Password</AndroidSigningStorePass>
<AndroidSigningKeyAlias>Alias</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>AliasPassword</AndroidSigningKeyPass>
On debug & release Part.
Then you can edit them on VS Windows.
Hope I helped someone.
See ya
In my case this was link to the "Sign the .APK file using the following keystore details" option as Hein Andre Grønnestad mentioned.
The location was not correct.
I wanted to put a path that could work for everyone at work so I used $HOME/Library/... instead of /Users/Me/Library/...
The problem is $HOME doesn't mean anything special for java so the keystore file could not be found.
Solution: use relative path or absolute path without $HOME variable or ~
For me, it was a problem with my Keystore. Follow this link to enable diagnostics. This will give you a more detailed error message in the output window. If it says that your keystore failed to verify, you will have to fix your keystore. This solved the problem for me.
In my case solved the problem by signing the .APK whit the values signed into the keystore that we configured to create the APK file in Release mode.
I taked the Microsoft example in here
and here I put the same values
That way a solved my problem with
"java.exe" exited with code 2
But the real information problem was in output:
Failed to load signer "signer #1"
java.io.IOException: Invalid keystore format
At the moment I don't find the real solution to this problem but, this works.
Please Update your Visual Studio to Latest version, if you are still using an old version.
If you think there is no solution then go and enable the Multidex
In my case the one of keystore details was wrong, after saving-> cleaning -> building process it worked.
Try reset the keystore <AndroidSigningKeyStore> or change to false the key
>
<AndroidKeyStore>true</AndroidKeyStore>
Only to check. But remembering that it needs to be set to true.
After Clean and Rebuild the solution.
For me it turned out I had Eclipse Temurin JDK installed and that was being used. In VS Tools>Options>Xamarin I changed the path to Java Development Kit Location to from the Eclipse path to C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot.
Maybe more importantly, I discovered Eclipse Temurin JDK was being used by running:
msbuild /bl /t:"Restore;SignAndroidPackage"
in my solution dir and then opening the resulting msbuild.binlog and clicking on the few errors and a path with Eclipse stood out. Your problem may be different but finding it this way may be the key to solving it.
EDIT: My settings don't stick after closing and reopening VS 2019. At this point I started using VS 2022 and don't have the issue.
Note: Multi-dex is enabled.
After 5 hours of looking or an answer, this is the conclusion I've found -
Enable diagnostic MSBuild output within Visual Studio, so you can see more details about your error:
Click Tools > Options...
In the left-hand tree view, select Projects and Solutions > Build and Run
In the right-hand panel, set the MSBuild build output verbosity dropdown to Diagnostic, Click OK
Clean and rebuild your package. Diagnostic output is visible within the Output panel.
If your error shows "java.io.IOException: Invalid keystore format", you are probably using an outdated Java sdk file, so do next:
Open Visual Studio and update the Java Development Kit Location to
point to the new JDK under Tools > Options > Xamarin > Android
Settings > Java Development Kit Location:
Be sure to restart Visual Studio.
My experience is...
I updated the following elements:
Xamarin.Android.Support.Design
Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.AppCompat
Xamarin.Android.Support.v7.CardView
Xamarin.Android.Support.v7.MediaRouter
from 26.1.0.1 to 28.0.0.3
Then, after it started the issue with:
"java.exe" exited with code 2 Xamarin.Android project.
I just ticked the Enable Multi-Dex inside the Android project property. I am using VS 2017 in windows system.
What I got going on in the project is a Cordova project that uses gradle to build. I created an android plugin that calls the Go script in the form of an .aar. All works with the simple hello world.go .aar. So I know that everything works. But adding in the selphyprint.aar it crashes with "Unsupported flags DT_FLAGS_1=0x9" error in adb logcat.
It's up at https://github.com/pbdesign/selphy. The full project is at https://github.com/pbdesign/printproject with an installable apk in the android folder of the com.photobooth project directory.
If you have any ideas, I found some similar error messages that are connected to android linker but don't know if they are related. Also any ideas on how to debug such an error would be appreciated.
This is not an actual full answer, but as a hint, DT_FLAGS_1 is a Binutils custom dynamic section entry (see the ELF standard).
These are produce by Binutils ld during link.
The 0x8 bit in particular is defined as:
#define DF_1_NODELETE 0x00000008
inside include/elf/common.h in Binutils 2.29.1.
I would then try to determine from Binutils source / docs what DF_1_NODELETE does to understand what is happening.
That flag is also mentioned at: glibc : Test if lib as DF_1_NODELETE flag or if lib has unique symbol
I use JavaCV 1.1. I have added jar files (javacv.jar, javacpp.jar and opencv.jar) and *.so libraries to my project in Android Studio. I succesfully build and run my app on Android 5.1 phone, but when i try use functions, that used OpenCV i get error:
java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader[DexPathList[[zipfile"/data/app/com.example.dogan.ligntningshower-/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libopencv_core.so"
I try to add
static {
System.loadLibrary("opencv_core");
System.loadLibrary("jniopencv_core");
}
but it's no work. How to fix it?
I just add *.so libs to folder /app/src/main/jniLibs/armeabi and now all works fine!
if someone still looking for the answer, first you should check if you added correct files to jniLibs folders. heres a complete tutorial :
A Beginner’s Guide to Setting up OpenCV Android Library on Android Studio
second, if .os files are at their places in each and every folder then you should only change the names to the name that is showing up in the compiler error.
in my case the names were libopencv_java3.so and yet the compiler was saying couldn't find "libopencv_java343.so" . after changing the name to libopencv_java343.so it worked.
I was trying to use opencv library, so I imported one of its projects in Android Studio and when I tried to run it I got this error:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)
So I downloaded the ndk and I addes this line to the local.properties file where it became:
sdk.dir=C\:\\Users\\skoon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\skoon\\AppData\\Roaming\\IDM\\android-ndk-r10d
but I still got this error which I didn't understand:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code:
2
Output:
make.exe: *** No rule to make target 'C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni', needed by `C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'. Stop.
I didn't change anything in the code, so what should I do? do I need to change or add any variables to point to the ndk?
P.S. This is my first time trying to build Android application so I don't have any experience.
Thank you in advance.
UPDATE:
To import the project I just used import project from file, then I synced the gardle, and run the project.
the package that I downloaded from opencv was the Android one, and I tried to use the face detection sample.
when I run it I got the error above.
You need to setup OpenCV librairies for your project. You can follow the instruction here.
OpenCV sample projects haven't support gradle officially. I think it will be easier if you start a new project and configure it to work as in examples.
I have implemented a tutorial project using Android Studio + NDK + OpenCV. You may have a look. https://github.com/quanhua92/NDK_OpenCV_AndroidStudio
Install NDK in your SDK manager, if you already installed open app's "build.gradle" replace these lines
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jni/'] } }
to
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains)
jni.srcDirs = [] //disable automatic ndk-build call
}
I'm tried to configure OpenCV and its fixed