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

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?

Related

Android errors throughout project

I've got a project from Github, that I'm viewing in Android Studio (3.0 Preview). When I build the project I get 0 errors but when I'm viewing the projects files, I get a lot of errors about not matching Class types.
Examples
Wrong 1st argument type Found 'android.support.v7.appCompatActivity' expected 'android.App.Activity'
on
Utils.patchFiles(outerClass, TAG,
new Utils.DesiredFilesKeywordGetter(), type2files);
Cannot resolve method startActivity(android.content.Intent)
on
startActivity(intent)
even I had the same problem once.
In your android studio gp to
File ->Invalidate Cashes / Restart
Then Clean and Rebuild the app again.
Hope this will solve the problem.

Visual Studio 2017 - Xamarin - The file "obj\Debug\android\bin\packaged_resources" does not exist

I'm fighting with that issue for 2 days already and can't find any solution.
I have an Xamarin Android app in Visual Studio 2017 consisting of three projects:
Xamarin.Android project (main one)
Android-specific unit tests run on the device - project of type NUnit 3 Test Project (Android) created using NUnit Templates for Visual Studio
Platform-independent unit tests project (project of type Unit Test Project (.NET Framework))
Everything worked just fine until now. When I selected my main project as the Startup one, my app was deployed to the device/emulator. When I selected my Android-specific unit tests project, the test project was deployed and unit tests executed by nUnit Xamarin Runners on the device/emulator.
However few days ago I updated my Visual Studio 2017 with the newest available update and now, when trying to build this android-specific unit tests project I get the following error:
The file "obj\Debug\android\bin\packaged_resources" does not exist.
I've searched everywhere, including this and this SO topics. I also totally reinstalled Visual Studio 2017 and Xamarin with Android SDK included. Nothing helped. From what I read I suspect there is something wrong with the versions of Android SDK Build-tools I have installed. Here's what I have currently installed in SDK Manager:
As the other SO threads suggested, I tried uninstalling the newest Android SDK Build-tools (25.0.2) and installed version 23.0.3 (all my projects target Android 6.0), but it also doesn't help, I still have the same error.
Maybe it's worth adding that this issue may have started to happen when I tried to implement RecyclerView in my app reading this tutorial, where they suggested to install Android 7.1.1 (API 25) in SDK Manager. However I undoed my all changes after that and even reintalled VS2017 + Xamarin.
Do you have any other idea why this can be ? I'd really appreciate any help. Thanks!
EDIT 2017-04-09:
Egh, I removed VS2017, installed VS2015 with brand new Android SDK and still the same issue :(
I've finally found what was the issue. It wasn't related to any component from SDK Manager or VS version.
Following localization tutorial from developer.xamarin.com, I played a bit with Strings.xml in my Android project. I wanted to have my Activities Label taken from resources as well, so in the ActivityAttribute I defined:
[Activity(Label = "#string/peopleListTitle")]
and added this value in Strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-------Other resources values ----->
<string name="peopleListTitle">People List</string>
</resources>
In that case my build is failing with above-mentioned error:
The file "obj\Debug\android\bin\packaged_resources" does not exist
When I change ActivityAttribute to use a string directly:
[Activity(Label = "People List")]
the build is passing without any issues.
I managed to find a solution, but actually I don't know why it's not building when I try to use Label text defined in Strings.xml.
BTW, I managed to find what's the problem by setting build output verbosity to Diagnostic in Tools -> Options -> Projects and Solutions -> Build and Run which gives a detailed info why the build failed in the Output window.
I had the same problem. After removing the dash "-" sign from the image file name, the problem is solved. Bad error message! It should not be:
The file "obj\Debug\android\bin\packaged_resources" does not exist.
Writing an error message like this causing the Developer to think about something else while the problem is the illegal file name.
I had the same issue when I added a new image as a resource.
There was a '-' in the file name (Invalid resource name character). I renamed & removed that character and all good.
Resource name can only consist of 0-9,a-z or A-Z or combination of any.
I had the same problem, and i removed all image file name have "-" character. My problem solved
Another reason for this error is that you may have a float number as your version number. In my case I changed it to a integer and everything worked fine. (I found the error by switching the build output to Detailed)
Simply it worked.
In one case I copied and pasted previous working "packaged_resources"
in the bin folder.[the problem was it did not reflect the UI changes]
Other I opened the visual studio as
administrator.
Next changed the "Minimum target to Android" to lower
apis in the project properties windows.
I suggest not touching the code behind of the design. If you get this error simply pull some button from the tool bar into the design and visual studio will come to its consciousness that there is change in UI. Next click on save all so that it make necessary change in the designer file.
Mine was a different solution (and only half a day lost): I was having trouble getting Hockey app to match crashes against the correct version of the app and realised it uses VersionCode not VersionName so I change my code to "0.0.34" the same as the name. For some still unknown reason the app built and deployed to devices for about 3 days before I started getting this error The file "obj\Debug\android\bin\packaged_resources" does not exist. Setting it back to a numeric value fixed the problem.
I found the problem by looking back through my GIT logs and rebuild each push until I found the one that caused the problem.
It just because the Version Code,I set Code by '1.0',The file "obj\Debug\android\bin\packaged_resources" does not exist.;And I set it by '1',everything is ok.
Had the same error, the way I got over it was crank up the Android SDK manager and install all updates and remove any obsolete packages. This happened to me because I was targeting something newer which was not installed.
Check to see if there are any unused entries in resources.designer.cs if there are any manually remove those entries.
This will fix the issue.
After following several online suggestions - updating SDK, updating Xamarin etc - none of which worked for me.
Finally found that I had an activity for a Android provider to Alarm clock in my AndroidManifest file as below
<activity
android:name="com.njcommuter.droid/android.provider.AlarmClock"
android:label="AlarmClock"
.....
/>
Removing this line - and rebuilding worked fine without any errors and was able to deploy solution successfully.
Note : testing this by putting the line back, and I get same error again on rebuilding.
It can be linked to using any android provider which creates the package for it, not necessarily AlarmClock only.
This error is, somewhat of, a wrapper for what can be multiple reasons that that the file was not created. The key is to look in the detailed output and look for the underlying error causing the file creation failure.
In my case, I had corrupted icon.png files (generated right from from the VS xamarin nunit template, no less!). Once I put in valid png files, everything was built fine.
Another reason for this error, if that the android NDK (not android SDK) isn't right, change de version can resolve the problem: go to Tools/Options/Xamarin/android Configurator and change de folder, in my case I've three, the last one can't compile, but the second folder with version xx.r11c do it.
For me it was Target Android Version.I had it set to
but changing it to Compiling version(for me it was the latest platform) resolved the issue.

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

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

Conversion to Dalvik format failed with error 1 with javax/net/SocketFactory.class

Encounter this problem when trying to Build Project getting such output in console:
[2010-07-19 23:29:23 - myProject]
trouble processing "javax/net/SocketFactory.class":
[2010-07-19 23:29:23 - myProject]
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2010-07-19 23:29:23 - myProject] 1 error; aborting
[2010-07-19 23:29:23 - myProject] Conversion to Dalvik format failed with error 1
I was looking for my project to use the package javax, not found, clean all also does not help. what I am doing wrong?
Update
Sorry guys, but I could not find good fix for that, I want to emphasize the fact, that i dont use SocketFactory class in my project at all! source code was not changed before this problem, and that's why i think that problem in eclipse or adt or something else, BUT if i use ant(generated by sdk) to build this project there is no problem!!!
I solve this problem by removing Eclipse, Android SDK, Eclipse workspace, and just reinstall them, after this all works fine for now.
Hope this will help someone.
I had the same problem..
This worked for me
project-->properties->java build path->libraries-> remove all including android jars
now go the project browser, right click on the project you are working on,
then android tools---> fix project properties...
do a clean and then build...
I solved the problem (at least for me).
Here's what I did:
Go to Project » Properties » Java Build Path » Libraries
Remove all except the "Android X.Y" click OK.
Go to Project » Clean » Clean projects selected below » select your project and click OK.
That did the trick for me.
Hope it works for you as well
Update: well actually I might have to retract my opinion.. the actions removed the error messages but now I am missing certain classes and methods... arggghhhh
I just restarted Eclipse, and the error didn't appear anymore!
I had the same problem,and solved it as follows:
First clean all jars; (This problem must because your some jars)
Delete the project;
Reimport project;
Make sure your sdk is right, and project select one sdk version;
(This is my issue to solve the problem) Right click your project, and select "build-path", next select "add Librarys", and add your private jars;
clean-build, the problem has fixed;
I just had the same problem and I tried all of the solutions listed here with no success (I was starting to get annoyed). Then I removed the project from the workspace and then imported it again, and there were no problems!
This happened to me this way,
I have a quite an old project which I had to start working again today. I use 'Universal Image Downloader' library for basically every project where I have to deal with lots of images. So in this old project I had the source files of 'Universal Image Downloader' included to it's 'src' path. Back then I was a newbie and slowly I started developing my own library which could handle every day simple Android development tasks very easily. Obviously I included the 'Universal Image Downloader' to this.
After dusting off the old project today the first thing I did was to reference my library to speed up the development process but as I was trying to debug I ran into the "Conversion to Dalvik format failed with error 1" over and over again. First I thought it was the support library but even after clearing all libraries and adding only mine and doing a quick 'Fix project properties' I still got it. After trying various solutions I noticed this in the console "java.lang.IllegalArgumentException: already added: Lcom/nostra13/universalimageloader/cache/disc/BaseDiscCache;"
It was as simple as that... I'm trying to compile a class which has already been compiled.
Solution : I just simply removed all the class files I got from 'Universal Image Downloader' library from the 'src' directory. Since my library references "Universal Image Downloader" library the old project started working just fine.
Hit same problem shown on your log when trying to run an example project which was imported into eclipse.
Additional Info: in eclipse's Problems View I see the following error:
"The project cannot be built until build path errors are resolved"
In my case the imported project find the libraries just right(by just right I mean I can see the external path to each of the android libs in this case 2 libs, android.jar and maps.jar). So no shuffling of libs in my case, but might be your problem.
I followed Spock's suggestion of cleaning the project which I had to clean multiple times until it somehow resolve its issues. After, issue was solved I had to specify an AVD for the project to run and soon after was up and running on the emulator. Also, note that my eclipse is set up to Build Automatically.
In my case I'm not missing any class files or anything after the clean as the build is properly generating them.
Regards!
I was getting the same error. My problem was that i had an android device hooked up to debug with. As soon as I unplugged it I was able to export.
The answer I found was checking the source and library build path in the project's properties. Most likely there will be a duplicate as in something being referenced in both the source and library tabs. So delete the extra in the source tab and then clean the project and you should be good to go.
Either:
javax.net.SocketLibrary is in your source code, or
javax.net.SocketLibrary is included in a JAR file in your project
Under certain conditions it gets its knickers in a twist and the best fix I've found is to remove referenced jars, clean, add them back in and then compile again.
I believe the error can be caused by including the same classes twice.
This error will also occur (and you won't be able to get rid of it by cleaning) when using classes that are not part of the Android environment.
To summarise the information in the link bimbim.in provided (well my understanding when I glanced over it)
The Android Davik VM tries to compile the jars but finds some stuff that it can't compile to .dex files
so
Just create a "lib" directory in the root of the project (where the src, bin res directories are) and add them to the build path. Project Properties... Java Build Path... Libraries.. Add JARs..
I could resolve this issue by creating a new project, looks like the some project settings were creating this issue and could not really find the root cause for that. But, dumping the existing source code onto the new project resovled this issue. If anyone has found the root cause for this problem pls do let me know.
I had the same problem and solved it as follows:
- Go to Project/Properties/Java Build Path/Libraries and remove all JARs except Android
- Do a project clean
- Add the JARs again as External JARs (first time I added them internally, so that might be the problem)
After that the error was gone.
I solved the problem by updating available packages in the Android SDK et AVD manager. No need to remove Eclipse.
Whenever the Project is having the ambitious data. This problem is caused. May be android can't able to find which one choose.
From what I understand, this same cryptic error could be caused from a wide variety of reasons. I've got "Conversion to Dalvik format failed with error 1" error too. In my case the problem was that for some reason Project -> Properties -> Java Compiler was not set to "Enable project specific settings" with proper Java 1.5 settings, but was left to defaults instead (1.6 in my case). Debug, build and test on devices/emulators worked fine, but export always failed with the above error message.
If unsure about the proper settings, create the same project on some alternative location and just copy all needed files from the old project into the new one. This fixed the issue for me.
The next problem with the same error message came from using proguard. Updating to the latest version by replacing the one that came with android sdk, fixed that.
Hope this helps
My problem was having a jar file in my src folder. Removing jars from the build path works, but only if you don't need the jar in question. For people who need the jar in question, make sure that your jar file is not in the project folder (maybe just src subtree, but I would keep it separate to test). Put it on your desktop or something and try the "Add external jar.." option. Be sure to remove the jar from the project filesystem before adding another external. Having both is what causes the problem.
I have done it as the instruction of the first answer and it works.(Linux)
I think the problem may caused by SDK or ADT updates.
I do have to clear all the lib in Java Building path and then use android tools to fix the project. After cleaning and rebuild, it works as before.

Categories

Resources