Xamarin android project "java.exe" exited with code 1 - android

I want to build my xamarin android application with android 12 target framework on release mode. The build fails with the following
"Xamarin.Android.D8.targets(51,5): error MSB6006:"java.exe" exited
with code 1."
error.
Solutions I've tried so far are :
1 - Download the latest proguard version and replace the files inside /android-sdk/tools/proguard and create a proguard config file under android project making sure the file is saved with UTF-8.
2 - Make sure all the nuget packages are compatible by creating a blank sample project and adding each nuget from my original project and make sure it builds.
3 - Delete bin and object files and rebuild the project.
Doing some online research that I've found out that this particular version (Xamarin.Android.D8.targets(51,5)) of the 'java.exe exited with code 1' error type is mostly associated with either proguard or incompability however I am unable to locate the source of the problem, any kind of help is appreciated.
Here are some relevant information:
I do have the msbuild output level set to diagnostics but i don't think i can share the whole 260k line output file. Linking is set to "Sdk assemblies only".
SDK
JDK
Android Options
6 > Done executing task "WriteLinesToFile".
6 > Done building target"_CleanRecordFileWrites" in project "TestApp1.Android.csproj".
6 > Build FAILED.
6 >
"C:\Users\TestUser\source\Workspaces\TestApp1\TestApp1.Android\TestApp1.Android.csproj"
(Rebuild;BuiltProjectOutputGroup;BuiltProjectOutputGroupDependencies;DebugSymbolsProjectOutputGroup;DebugSymbolsProjectOutputGroupDependencies;DocumentationProjectOutputGroup;DocumentationProjectOutputGroupDependencies;SatelliteDllsProjectOutputGroup;SatelliteDllsProjectOutputGroupDependencies;SGenFilesOutputGroup;SGenFilesOutputGroupDependencies
target) (1) ->
6 > (_CompileToDalvik target) ->
6 > C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.D8.targets(51,5):
error MSB6006: "java.exe" exited with code 1.
11 Warning(s)
1 Error(s)
6>Time Elapsed 00:00:58.23
========== Rebuild All: 5 succeeded, 1 failed, 0 skipped ==========
There is no output from proguard inside the build output.

I've found the problem. The project was developed on android 11 and could build without a problem, the problem began when the target framework version was changed android 12, first the build error was:
'Xamarin.Android.Support.v4' is using '[assembly:
Java.Interop.JavaLibraryReferenceAttribute]' , which is no longer
supported. Use a newer version of this NuGet package or notify the
library author.
So we made sure that all nuget packages could run on android 12 than the build error changed to:
is also present at androidmanifest.xml:22:18-91 value (android.support.v4.app.corecomponentfactory)
this is was just one of the several java errors and all the errors were related to android.support.v4.app library. So during my first research I've found from the in xamarin community that some were able to solve their problem by adding the code :
tools:node="replace"
to their AndroidManifest.xml file under the <application> tag. So I did just that to see the results and the error than changed to:
"java.exe" exited with code 1
after going back to the first "android.support.v4.app" error and doing some more research about it online I've found that android studio users could solve these type of errors by setting the "useAndroidX = true" in their build.gradle file. Not having a build.gradle file in my project I've just decided delete the code I previously added to my AndroidManifest.xml and to add the "Xamarin.AndroidX.Core" Nuget package to my android project, after doing so the error changed to:
Could not find Jetbrains.Annotations
So after also adding the "Xamarin.Jetbrains.Annotations" nuget package to my project ,it now builds without an error.

Related

XAMARIN ANDROID APK BUILD ERROR

This error keeps showing when I try to generate an apk file via visual studio:
Error "aapt.exe" exited with code 1.
Error The file "obj\Release\android\bin\packaged_resources" does not exist
I hope you found a solution but I will reply just in case anyone arrives to your question as I did.
Seems like there are number of reasons why this error can come up but the most common (also in my case) was a resource which had an invalid name. I found out the exact problem and which resource it was that was incorrectly named by enabling Detailed verbosity for MSBuild project build output. You can do that by going to
Visual Studio Tools > Options > Projects and Solutions > Build and Run > MSBuild project build output verbosity
Set the verbosity to Detailed and Rebuild your android project. Then inspect the Output window and hopefully you will get closer to finding the problem.

non-whitespace before first tag. File MDAVSCLI?

I got this error while compiling my app I'm using Apache Cordova and visual studio 2015 as an IDE. I've looked for the MDAVSCLI file in my project but i can't find it. I think it's to do with the compliing the app on the android platform as when I run it on iOS I don't get the error.
The error I get is:
Description: Non-whitespace before first tag.
Project: C:\Users\Daniel\Documents\Visual Studio 2015\Projects\Shake it up\Shake it up\MDAVSCLI
Line: 1
Column: 1
Source: Build
I have no idea what to do and nothing I've looked at seems to be specific to my problem.

Android App Compile Not Generating Package Resources

When attempting to compile my Xamarin.Android app I get the compile error:
Error 3 The file "obj\Debug\android\bin\packaged_resources" does not exist. MyApp.UI.Droid
This error occurred after I made some changes (added some new classes - cannot remember what it was). But I didn't change any project settings, nor go delete actual files in the obj folder.
What is the cause of this error and how can I fix this?
Some information that may be useful:
The project is a Cross-Platform PCL project - Core, Android, and iOS Projects
The project uses MVVM Cross
I encountered the same issue. Ensure that your resource files do not include any special characters
The actual error you may be encountering is:
Invalid file name: must contain only [a-z0-9_.]
Change your build output verbosity in visual studio to see better log output.
I´ve had the same issue.
Then i´ve reviewed my resource file names.
Solution:
One file was using "-" in it´s name. (invalid character)
Then i replaced for "_" (underline).
PS:
=> file name: must contain only [a-z0-9_.]
You will need to grub down by switching on Verbose output. What is stopping the generation of packaged_resources?
In VS2013 choose Tools --> Options --> Build and execute, choose verbosity Diagnostic.
In VS2015, the same option is in Tools --> Options --> Projects and Solutions --> Build and Run.
In my case, it was a hyphen character in the name of the action property of an Intent filter, but choosing verbose output will point you to the line that has the problem.
Follow the steps below to identify the problem:
1 - In Visual Studio: Tools> Options> Projects and solutions> Build and Run.
1.1 - In the dropdown: MSBuild project build output verbosity:> Diagnostic.
1.2 - Close the dialog box.
2 - View> Output (Ctrl + W, O).
3 - Run the build or rebuild.
In the output find the line:
C:\Program Files
(x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1665,3):
error MSB6006: "aapt.exe" exited with code 1.
What is just above this error is what caused the error.
i also found that removing the packages in Tools/Preview Channel and Android N AND ALSO Android SDK Build Tools rev 24, done a build and worked.. This is a complete new portable project/android/ios
Another possibility is you have an issue with the installed Android SDK build tools. For me, when I removed the package for Revision 24 it worked.
From Xamarin Forums:
First of all go and deinstall preview tools in your android sdk
manager. If you havent installed it but still get the same error then
go and deinstall Android SDK Build Tools Rev. 24.
The Problem we have here is that, if you have Appcombat, RecyclerView
or something like that in your project, the library rev of these
librarys are below rev 24. They are still on 23.2.1 but not on rev 24.
So if you installed Build-Tools Rev 24 and want to build your project
the build cant find the rev24 resource package of your librarys.
You can check it on your own Go in the SDK Manager and check "Obsolete" Then go to the folder Extras and there you can see
"Android Support Library (Obsolete) Rev 23.2.1. And then check if
there is Android Support Library Rev 24 in your Extras Folder. No? And
thats the Problem here. We got the Update for Build Tools to early and
have to wait for Library Update. Then we all can use Build Tools 24!
So only update to BuildTools Rev 24 when we got an update for support librarys and have the rev24 librarys.
Basically the problem is with special character of Resource FILE NAME.
In my case, I am keep getting error "The file "obj\Debug\android\bin\packaged_resources" does not exist.":
..\Resources\drawable\company-app-log.png having -(hyphen) between alpha characters is the root-cause of the issue.
Using Xamarin Studio here -
Sometimes this is caused by AXML errors.
Which if you turn on detailed / diagnostic in preferences you can
search the build output (or your packaging output) for the word ERROR.
For example, somebody checked in some AXML line(s) with -
android:Text="something"
and the uppercase T was causing this error -
Resources/layout/Somefile.axml(11): error APT0000: No resource identifier found for attribute 'Text' in package 'android'
Fixing the errors fixed the original message.
Firstly, i suggest you change "show out put from" Build to Xamarin to see the real error and its details as seen in my case
At first
And then
please make sure you installed your NDK properly. That was the issue with mine,
and please make sure the NDK directory is also set
hope this helps someone
I just lost 7 hours of my day.. You know what I did?
Project.Droid -> Resources -> RightClick on the Resource.Designer.cs -> Delete
I did fu****n' works ! ><
EDIT
Omg it did comes back... Why does Windows has all time so much of bugs... seriously..
Same annoying problem with me!
But I found a solution: read carefully this article:
https://gxconsultancy.wordpress.com/2016/04/04/to-use-xamarin-or-not-to-us-xamarin/
In short:
Make sure you have JDK 32bits version 8 at least - same for the JRE, included in the JDK installation kit from Oracle;
Set your project for using the Xamarin debugger (right-click your project, hit Properties / Android Options / Packaging / Debugger);
And now the most weird: delete the app/Resources/drawable folder; have a working Xamarin project and copy its "drawable" folders to the erratic project (usually there are several subfolders, like drawable-hdpi, drawable-mdpi and so fort).
Rebuild your Android project.
I had the problem so I deleted build-tools 24.0.0 and I used build-tools 23.0.3 and the problem solved. Try it!
make sure that your resources don't have any special character or start with number
Encountered same issue in VS 2015 and Xamarin 7.2.0.7. In my case, the issue happened just suddenly, and turned out the issue caused by wrong element name in axml, traced using Tiago's answers above.
So I didn't find the line Tiago mentioned with aapt.exe, but I then I tried to search for keyword failed in output. Then I found one telling me about margin. In android, margin is set using android:layout_margin. I played with element and forgot and put android:margin instead, thus also why it happened so sudden after so many successful run. Fixed it and the build succeeded.
In my case the error was caused because I set the version number in the manifest to 1.0. Apparently the version number must be an integer.
Had the same problem. My error was in the manifest: I had Version Code (Version number) set at "1.0.0" and it wasn't allowed. It only takes integers so I had to revert to "1".
I mixed up Version Code and Version Name.
For me this error was caused by having an invalid attribute value in a layout xml. I had
android:id="button"
changing it to
android:id="#+id/button"
fixed the error.
Not sure if this is a late answer, but this specific error message occurs for one of the two reasons:
(Most probably the case): In your layout file, you may have mentioned a resource (drawable/image) incorrectly. For example, the image was in the mipmap folder path but you have pointed it wrongly to the drawable folder path.
Per many comments, there could be a hyphen or special character in one your resources' names or it starts with a number. However, please note, in this specific case, you will mostly see a aapt.exe has stopped or appt.exe has exited with error code 1 error. I am not sure if you will get obj\Debug\android\bin\packaged_resources not found error. My experience says that point 1 above is the case.
Got this error in Visual Studio 2017 Xamarin android project on Windows.
After lot of experiments with resource's files I found, that filename length and extension of image file in the drawable folder affect the result of compillation!
drawable/abcde.png - compilled ok
drawable/abcdef.png - error, "obj\Debug\android\bin\packaged_resources" does not exist
If rename image to file without .png extension, compilled without errors.
Spended a lot of time and was confused :-/
I had the same problem. To solve I had to remove all nuget packages from droid project, and reinstalled xamarin.forms again (has to be same version used in other projects).
had the same issue. This was because i had an .png file that had a "-" character in it's name. Just enusure any of your resources don't have the "-" hyphen character

Qt compiler reports invalid build tools version for Android

I have been developing Android applications using Eclipse/Android Studio. Now, I am exploring building an application using QT. I installed QT and configured it for Android as explained at http://qt-project.org/wiki/Qt5ForAndroidBuilding. I later my first Android app using "QT Quick Application" template. When I compile it from QT Creator, I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\MyQtApps\build-MyTest1-Android_for_armeabi_v7a_GCC_4_8_Qt_5_4_1-Debug\android-build\build.gradle' line: 39
* What went wrong:
A problem occurred evaluating root project 'android-build'.
> Invalid revision: build-tools-21.1.2
Android build tools version 21.1.2 is present on the machine. In fact, my SDK and all other Android tools are completely up to date.
Next, from the options dialog, I turned "Use Gradle" off and entered the path for Ant executable. After that, I proceeded to create a new project. This project builds and deploys fine on my mobile device.
Looks like the problem is with Gradle integration. For now, I can simply go with Ant but would be nice to have it fixed. Any suggestions? Regards.
For those who are running into this problem (and I assume this includes everyone who is using Qt for Android development), the solution is to fix Qt-generated gradle.properties file. This file contains the following line:
androidBuildToolsVersion=build-tools-21.1.2
File build.gradle tries to use this variable as:
android {
...
buildToolsVersion androidBuildToolsVersion
...
}
Function buildToolsVersion expects a value such as 21.1.2 and not build-tools-21.1.2. So the fix is to edit gradle.properties file as:
androidBuildToolsVersion=21.1.2
I still don't know where Qt Creator picks up 21.1.2 from. In my case, I used the following setting:
androidBuildToolsVersion=23.0.0
Now, things work as expected.
In addition to Peter solution:
You can change in the android/gradle.properties the androidBuildToolsVersion to the desired one.
Note: You have to edit the file via shell because it doesn't appear in the qt creator (at least in the 5.9 version)

How to solve the Dalvik error in adding libs to another project to make a Lite version of my Android app?

In my app, I have to have two version: Full and Lite.
I am following these tutorials:
http://bitowl.wordpress.com/2011/07/06/tutorial-how-to-make-full-and-lite-versions/
http://blog.donnfelker.com/2010/08/05/howto-android-full-and-lite-versions/
So, I build my full version, and make it a library. This full version uses some other libs, needed to some components.
Then, I create a new project and added the lib created. The problem is when I try to run my lite version, eclipse gives this error:
[2012-12-13 13:58:13 - <app> Lite] Dx
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lnet/simonvt/timepicker/R$attr;
Conversion to Dalvik format failed with error 1
The simonvt/timepicker is one of the libs that I use in my full version.
How can I fix this?
Thank you!
Do the following:
Right-click on your project and choose Build Path -> Configure Build Path,
then go to order and export section
If simonvt/timepicker has a checkmark against it, then deselect it.
I believe that the problem is that the library project is already added and you might be trying to add it again.

Categories

Resources