com.android.ant.SetupTask cannot be found - java

I would need to build one android app from command line. I successfully compiled its jni part, but cannot build Java part. ant prints the following (paths have been removed):
/.../build.xml:69: taskdef class com.android.ant.SetupTask cannot be found
using the classloader AntClassLoader[/path/to/sdk/tools/lib/ant-tasks.jar:/path/to/sdk/tools/lib/manifest-merger.jar:/path/to/sdk/tools/lib/common.jar:/path/to/sdk/tools/lib/guava-13.0.1.ja r:/path/to/sdk/tools/lib/sdklib.jar:/path/to/sdk/tools/lib/layoutlib-api.jar:/path/to/sdk/tools/lib/kxml2-2.3.0.jar:/path/to/sdk/tools/lib/dvlib.jar:/path/to/sdk/tools/lib/bcpkix-jdk15on-1.4 8.jar:/path/to/sdk/tools/lib/commons-compress-1.0.jar:/path/to/sdk/tools/lib/httpclient-4.1.1.jar:/path/to/sdk/tools/lib/httpmime-4.1.jar:/path/to/sdk/tools/lib/bcprov-jdk15on-1.48.jar:/path /to/sdk/tools/lib/httpcore-4.1.jar:/path/to/sdk/tools/lib/commons-logging-1.1.1.jar:/path/to/sdk/tools/lib/commons-codec-1.4.jar]
It seems that SetupTask is inside anttasks.jar, but it is not in my sdk directory. I tried to install all available sdks, tried to add ant-tasks.jar to the class path (it has similar name), but with no success. Is there any way how to install anttasks.jar, or is it replaced by something else? Or is SetupTask obsolete in some way?
I have run:
android update project ...
I tried to find answer by google but with no success for this particular issue (AntClassLoader is not empty, anttasks.jar is missing).
Thanks,
Daniel

Afaik the SetupTask ist obsolete in Android 2.3 and higher. So it seems to me like you're working with an old version of the build.xml. Since Android 2.3 and higher, there is a new template for the build.xml in the directory
your-android-SDK/tools/ant/. You can modify this one according to your needs.
Maybe this link will help you, it pointed me in the right direction:
https://sites.google.com/site/sokolkosta/internal-blog/includingadditionaljavaxpackagesinandroid23

https://stackoverflow.com/a/15719072/1343309
It worked for me.
rm MyProjects/NowRedux/build.xml
android update project --target 8 --path MyProjects/NowRedux

Related

"java.exe" exited with code 2 Xamarin.Android project

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.

installing openimaj's statistic package

I followed the instructions on this page - http://www.openimaj.org/tutorial/getting-started-with-openimaj-using-maven.html and created a project. However, it's missing org.openimaj.math.statistics package. I just wanted to use MeanAndCovariance method. How do I install this missing package? I'm on osx (Mountain Lion)
I just found out that I really don't need to follow that instruction that basically installed whole lot of unnecessary package. All I need is, download core-math jar file from this link - http://mavensearch.io/repo/org.openimaj/core-math/1.3 and adds to my project. Vola works like charm!

Unable to load class com.android.build.gradle.managed.NdkConfig$Impl

I just upgraded to AS 2.0 Preview 8 and I'm trying to build my old project. I updated it to be
classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha8'
and updated the gradle-wrapper.properties to use gradle-2.10-all.zip, but when I try to build my project I get a Java stactrace saying:
Unable to load class com.android.build.gradle.managed.NdkConfig$Impl
I'm using Java 8 to start AS as well as having that set as the JDK for the project. I was also having the same problem with Java7. What am I missing?
The problem with my project was due to a change in the gradle-experimental plugin:
+= no longer works for collections. Adding items to the list can be done with the 'add' or 'addAll' method. e.g. CFlags +=
"-DCUSTOM_DEFINE" can be replaced with CFlags.add("-DCUSTOM_DEFINE")
Changed those occurrences and the build finished successfully.
Oddly enough, this was fixed by simply doing a Gradle clean. Hope this helps someone else as this was not intuitive

Cannot resolve com.parse.ParseQueryAdapter

My current setup :
OS : windows 7
IDE : Android Studio (with updated SDKs)
Parse jar (v 1.10)
I am trying out an example for ParseQueryAdapter, and I run into this error on my IDE : import com.parse.ParseQueryAdapter; -> cannot resolve symbol ParseQueryAdapter
I want to try something similar to this example, and the import does not seem to go through because of the error.
If you need anymore information, please leave comments & I will respond.
PS : I am able to add com.parse.ParseObject without errors.
In your libs folder you'll find Parse-1.4.1.jar file.
Right click or control+click on it then 'Add as Library...'
Edit: Parse-1.10 does not have ParseQueryAdapter. You have to use Parse-1.4.1, which is included in that example.
ParseQueryAdapter was removed from the official Parse SDK and moved onto the Parse-UI libraries..
You can install them on via this link: https://github.com/ParsePlatform/ParseUI-Android
If we include 1.4.1, and keep 1.10.1 as well, it gives error because we cannot keep the same jar with two versions in the libs folder. And I think its not advisable to use just 1.4.1. I feel that ParseQueryAdapter is deprecated and we would just have to use the normal adapters. Any comments?

Compiling standalone selenium: Failed to load Main-Class manifest attribute from

I'm a total Java noob so please understand =) I need a quick advice on how to fix the issue.
I cloned the official selenium git repo, changed the code a bit (need to dump the page into some specified dirs), and tried to rebuilt it:
./go //java/server/src/org/openqa/selenium/remote/server:server:uber //java/client/src/org/openqa/selenium:client-combined:uber
It was successful but when I tried to execute it I got this:
$ java -jar build/java/server/src/org/openqa/selenium/remote/server/server-standalone.jar
Failed to load Main-Class manifest attribute from
build/java/server/src/org/openqa/selenium/remote/server/server-standalone.jar
Tried to check classpath, CLASS_PATH and CLASSPATH env variables (as a friend of mine suggested) - I simply don't have any.
At the same time, the pre-compiled standalone server from the official downloads works out of the box.
The official docs didn't help. There's nothing about it there.
So - I need a quick advice how to compile it? Thanks.
P.S. JDK 8 (latest), Mac OS 10.7
P.P.S. That friend of mine tried to build it by himself and he was lucky - he got a new build/dist folder where the target big file was. But in my case, the build folder is created, but there's not 'dist' folder in it.
Finally found the answer: I should have built it like that:
./go clean release
it's really strange that all the docs state I need to use these long /bla/bla/:uber things to get a whole single 'uber' server.

Categories