XAMARIN ANDROID APK BUILD ERROR - android

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.

Related

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

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.

Android Studio IDE exception can't open Layout Resources xml files

Android studio is throwing an null pointer exception related to the Android Support plugin when opening. As a result I can't open layout resources xml files.
I've tried
Invalidating Caches/ and restart
Cleaning/rebuilding project
Disabling Android SDK support plugin
Any help would be appreciated.Stack trace is below.
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at com.android.ide.common.resources.FileResourceNameValidator.getErrorTextForNameWithoutExtension(FileResourceNameValidator.java:135)
at com.android.ide.common.resources.FileResourceNameValidator.getErrorTextForFileResource(FileResourceNameValidator.java:117)
at com.android.ide.common.resources.FileResourceNameValidator.validate(FileResourceNameValidator.java:48)
...
Based on your answer, I think you should make sure you have every files in your project directories. Try to debug buy going to Analyze --> Inspect Code
and let it run for a while. Any errors will be marked as red. Check it if one of the files have missing references like your case above. More can be found here,
https://developer.android.com/studio/write/lint#studio and;
How Do We Configure Android Studio to Run Its Lint on Every Build?

Seeing errors in Android Studio 2.1.2

I'm an Android Studio noob and I'm confused about how it reports errors. I have a fairly large Android project - about 25 java source files - mostly Activities - and a similar number of XML files.
I do a Build > Clean Project and a Build > Rebuild Project, and the Gradle Console reports BUILD SUCCESSFUL. In the Messages tab it says:
BUILD SUCCESSFUL
Total Time 4.368 seconds
0 errors
0 warnings
But if I actually open up an XML file, e.g., the Android manifest.xml file, I see errors marked in red, such as
Cannot resolve symbol 'PlyListActivity'
and
Cannot resolve symbol 'ActivityMsgClass'
... those seem like errors to me. Yet the Android manifest.xml file is not marked or highlighted in any way in the UI - if I hadn't opened it in the editor I wouldn't have seen those errors. So short of opening up each of the 25 XML files in my project, how can I find out about such errors when I do a build?
Edit: Just to be clear - my question is not about what causes the errors listed in the manifest. My question is why does the build show 0 errors and 0 warnings, and is there any way in Android Studio to be aware of these errors/warnings short of having to open up each and every file (25 in my case) in the editor to look for them?
This is a very annoying bug, and it's been around forever. Unfortunanetly, there is no way you can fix it, this doesn't only happen to the Manifest but to the resources XML files too. However, your app will crash if there is a real error, not a warning.
However, there could be a way if you mess around Android Studio, I couldn't find this, but maybe you could:
Go to Android Studio. Go to File>Settings, alternatively press CTRL+ALT+S
Go to Editor>Inspections,now here, you can change all the errors in Android Studio to a warning, or nothing and vise-versa. This could solve your problem if you find your error in this window and disable it (Make sure it is Manifest Only). Otherwise, I hate to say the answer even for myself, there is no solution.
UPDATE: If you go to Analyze>Inspect Code you can see all your errors and warnings in your project.
This is not an error. This show both the class are not defined in your project as activity, but you have still defined in manifest as activity.
If you run the 'lint' gradle task, it should generate an webpage that details all the warning/error/issues it detects during build time.
Ran lint on variant debug: 11 issues found
Ran lint on variant release: 11 issues found
Wrote HTML report to file:///C:/Android/JsoupExample/app/build/outputs/lint-results-debug.html
Wrote XML report to file:///C:/Android/JsoupExample/app/build/outputs/lint-results-debug.xml

"java.exe" exited with code 1 Error while running xamarin.android app

I am new to xamarin.android apps.
i download the one maps project from http://developer.xamarin.com/samples/MapsAndLocationDemo/
and i'm trying to run the app in visual studio 2013, while debugging i'm getting error like "Java.exe" exited with code 1.
i'm trying to solve it but i failed.
i also faced some other problems, at last i solve those. but this error is still there.
when i try to find the error it show the code like below
<CompileToDalvik
DxJarPath="$(DxJarPath)"
JavaToolPath="$(JavaToolPath)"
JavaMaximumHeapSize="$(JavaMaximumHeapSize)"
JavaOptions="$(JavaOptions)"
ClassesOutputDirectory="$(IntermediateOutputPath)android\bin\classes"
MonoPlatformJarPath="$(MonoPlatformJarPath)"
JavaSourceFiles="#(AndroidJavaSource)"
JavaLibraries="#(AndroidJavaLibrary)"
ExternalJavaLibraries="#(AndroidExternalJavaLibrary)"
LibraryProjectJars="$(IntermediateOutputPath)__library_projects__\*.jar"
DoNotPackageJavaLibraries="#(_ResolvedDoNotPackageAttributes)"
ToolPath="$(DxToolPath)"
ToolExe="$(DxToolExe)"
UseDx="$(UseDx)"
AdditionalJavaLibraryReferences="#(_AdditionalJavaLibraryReferences)"
/>
File path location "C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets"
if any one face similar problem please help me to rectify the problem.
Thanks in advance.
It looks like the program was trying to allocate too much space to the Java Heap.
You can change this by going to the Android Project Options > Android Build > Advanced and then changing the Java Heap size to 1G.
You need to look closer in the build error logs. You'll find Progaurd complaining about several classes.
What you need is write the following lines:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
Into file named proguard.cfg. Add it inside Android project in the solution. Make sure you set Build Action to ProguardConfig.
Finally, make sure you save file as UTF-8 and NOT UTF-8 BOM
I encountered this problem on a colleague's computer after he updated Xamarin. The problem ended up being that his old sdk was installed under Program Files, while the update installed it under AppData. Changing this folder under Options > Xamarin > Android in Visual Studio solved the problem for him.
This can happen if you have syntax errors or unsupported characters within your Proguard.cfg file.
In my case, removing the comment in my otherwise empty Proguard.cfg file did not resolve the problem of an 'unsupported character'. Deleting the file altogether was a quick and dirty workaround.
Download latest version of JAVA JDK and change the reference in Tools->Options->Xamarin->JDK location to point to it (ie C:\Program Files\Java\jdk1.8.0_111).
Hope this helps.
Increase the HeapSize
From Visual Studio > right click Android Project> Properties> Android Options > Advanced> Java Max Heap Size > 1G
You can also try by going to Android Project Options > Android Build > Linker > Linker Behaviour set to Don't Link
I just had this problem. Rather than trying to fix it by increasing the heap size, I was able to fix it by going to Build -> Clean Solution, and then Rebuild Solution.
**Error : while running app “Java.exe” exited with code**
I resolved this by manually overriding the java heap size: In Visual Studio: Right-click on Project
->Click andriod properties
-> Click Android Options
->select Advanced tab
->Advanced android build settings
Set Java MAx Heap Size to 1G (Or larger depending)
The project now builds.
Hope this helps. :)
OR
Just resolved my problem by Unchecking Enable Proguard option.
Go To : Project Properties > Android Project Options > Android Build > Advanced Tab > Uncheck Enable Proguard

Proguard ParseException with Default proguard.cfg on Android

I am about to release an application but, while i was building it using Export Tool of Android SDK in Eclipse, i get the error below.
I didn't change the proguard.cfg.
It is in the root folder of my project.
I only add proguard.config=proguard.cfg to default.properties.
I read the forum and update proguard (just copied the files to the tools folder of Android SDK), but still I doesn't work. I couldn't figure out what the problem is with the 'Projects\Eclipse' ??
If you help me, I will be so glad...
[2011-08-08 02:32:46 - CoolProject] Proguard returned with error code 1. See console
[2011-08-08 02:32:46 - CoolProject] proguard.ParseException: Unknown option 'Projects\Eclipse' in argument number 9
[2011-08-08 02:32:46 - CoolProject] at proguard.ConfigurationParser.parse(ConfigurationParser.java:172)
[2011-08-08 02:32:46 - CoolProject] at proguard.ProGuard.main(ProGuard.java:484)
Yeah that is right, but also I did something that I didn't know :)
My solution was:
I updated to latest Android SDK.
I changed SDK path property under Eclipse: Window > Preferences > Android > SDK Location as something like c:\Progra~1\android-sdk. The Progra~1 can be used for writing Program Files witout spaces. You can use DIR /X command in command prompt on Windows to get no space versions of Paths.
I moved my Eclipse Workspace to a location without spaces like D:\
The changes above didn't enough to solve the problem. I got "Conversion to Dalvik format failed with error 1" error dialog witout any explanation on output console. Then I found that topic and did what that reply says.
Then it worked ;)
I am using Windows 7 Ultimate x86. I hope it works for others too.
Arda.
Your project path probably contains a space. This should be fixed in the latest version of the Android SDK (at least for the Ant build). Otherwise, you should use a path without spaces for the time being.

Categories

Resources