No properties are generated with Android SDK - android

I installed packages from the Android SDK manager, but when I open an xml file to edit a layout, I get unresolved errors When I drag and drop items from the sidebar, I get a log saying:
Couldn't resolve resource #dimen/activity_horizontal_margin
Couldn't resolve resource #dimen/activity_vertical_margin
"#dimen/activity_horizontal_margin" in attribute "paddingLeft" is not a valid format.
"#dimen/activity_vertical_margin" in attribute "paddingTop" is not a valid format.
"#dimen/activity_horizontal_margin" in attribute "paddingRight" is not a valid format.
"#dimen/activity_vertical_margin" in attribute "paddingBottom" is not a valid format.
Also, no properties show up when I view the menu. When I right click on the layout to set a different layout manager, I see the following. I installed the correct packages from the SDK Manager, including all tools, the Android 19 API, Android 18 API, and the Android Support library.
Here's my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
Where can I start by fixing these errors?

This is probably caused by a mix-and-match of some large, medium and small resolutions in your project but render the layout in a view not considered large enough. In this case, just change the render parameter in the graphical layout tool. Hope it helps.

Such layout errors usually appears after you've created new Activities/Layouts using IDE build-in tools/wizards (like New->Activity->Blank Activity with Fragment in Android Studio). At this moment Java and XML code is already created, but auto-generated code (like R.java file) isn't generated yet. What's why layout editing feature is not working - it requires valid R.java file with all your resources (in your case it's #dimen/*).
To fix this errors simply compile your project (which will force auto-generated code to be generated) and refresh layout editor window.

Related

How to use Android RRO to overlay a layout?

I'm trying to customize Android 10 AOSP Settings app (com.android.settings) using a Runtime Resource Overlay (RRO).
When using a RRO, I can successfully customize any string in Settings app by putting a new value in the RRO's file ./res/values/strings.xml.
However, I cannot manage to overlay not a string but a layout by putting the layout file in the RRO's ./res/layout/ folder.
The RRO gets built, but the ids are different than the ones in the original layout, so after installing the RRO on device, the Settings app will fail to find the elements it expects in the layout file using findViewById().
For instance, I create a RRO containing the following bluetooth_pin_confirm.xml layout file (copied from Settings app source code and simplified) in its res/layout/folder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/pairing_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
...
</LinearLayout>
After installing the RRO on device, the Settings app will successfully inflate this file in BluetoothPairingDialogFragment.java
View view = getActivity().getLayoutInflater().inflate(R.layout.bluetooth_pin_confirm, null);
But then it won't be able to find the views by id:
TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
R.id.pairing_caption cannot be found so pairingViewCaption will be null
So it seems that the IDs in the layout file from the RRO are different than the original ones.
Indeed, when running aap2 dump on Settings app apk I can see:
resource 0x7f0a02e0 com.android.settings:id/pairing_caption: t=0x12 d=0x00000000 (s=0x0008 r=0x00)
While in the RRO I can see:
resource 0x7f010000 com.foo.settings:id/pairing_caption: t=0x12 d=0x00000000 (s=0x0008 r=0x00)
So yes, the Ids are different.
Now, it should be the whole point of the RRO when overlaying a layout to be able to match the Ids so to keep original Ids but change the layout around them. But how?
I've played a bit with aapt2 options --emit-ids and --stable-ids to try to force generated id to be equal to the one in Settings.apk, but that fails miserably as well:
error: can't assign ID 0x7f0a0303 to resource com.foo.settings:id/pairing_caption with conflicting ID 0x7f010000.
Note that this issue is specific to Android 10 and earlier. It seems that in Android 11 there is a new & better way to define mapping between ids in target and overlay package.
I'm pretty stuck here. Any suggestion would be greatly appreciated
On the link rro
you can find the following
Note: If you overlay a layout file, make sure all the IDs and app namespace attributes are included in both overlays.xml and overlayable.xml. For example:
<overlay>
<item target="layout/car_ui_base_layout_toolbar"
value="#layout/car_ui_base_layout_toolbar" />
<item target="id/car_ui_toolbar_background"
value="#id/car_ui_toolbar_background" />
<item target="attr/layout_constraintTop_toBottomOf"
value="#attr/layout_constraintTop_toBottomOf" />
</overlay>

Uri is not registered for layout in test resources

I'm new at Android testing and I'm trying to test a custom view in an android library and i'm using Android Studio.
I found here : Android: How to test a custom view? that I should use ActivityUnitTestCase and a mock activity.
I have put my xml layout inside projectname/library/src/androidTest/res/layout and my test activity know my layout R id thanks to this : Configuring res srcDirs for androidTest sourceSet.
My issues is in the layout content.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<eu.custom.customView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
In my case, "http://schemas.android.com/apk/res/android" display in red with an error "URI not registered" and the IDE doe's not recognize my custom view if I add it in this xml.
Is there a way to have this layout working without putting it in production code ?
Thanks
Well, in my Eclipse IDE your code looks correct (there are no red lines) may I suggest you to download the ADT-Bundle again or use Android Studio? I think your IDE is corrupted or something in your settings is wrong. Also check if you have downloaded the up-to-date SDK build tools.

could not resolve resource android eclipse

I am new in andorid development.
I have created my android first project according to http://developer.android.com/training/basics/firstapp/creating-project.html
And here is the code that I have as the project was created(no changes are done in code by me)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Here is the screenshot of the Graphical layout
http://imageshack.us/a/img35/5284/android1s.png
So, it looks fine for now, but if I want to change the text Hello world to , say, hello, so the code's part looks like android:text="#string/hello", I get the error
NOTE: This project contains resource errors, so aapt did not succeed, which can cause rendering failures. Fix resource problems first.
and
Couldn't resolve resource #string/hello, and the text in graphical layout becomes
#string/hello, as it is in this image
http://imageshack.us/a/img826/7735/android2p.png
But I noticed one thing:
If after this error I go to res/values/strings.xml and add String with name and value hello, like
http://img842.imageshack.us/img842/8108/android3s.png
The error disappears and I can see the word hello in the graphical layout.
I tried these so far
Using ctrl+shift+s like it is described here https://stackoverflow.com/a/14462434/932473
Closing and reopening Eclipse.
cleaning, rebulding
removing the entire project and creating again.
The values folder does exist in res.
None of these questions solved my problem
Eclipse could not resolve string resource error
Can't Resolve Android Resource Strings
UPDATED
If I write like this android:text="hello"
I get this warning in eclipse
Hardcoded string "hello", should use #string resource,
I do not get it every time I want to use some string like android:text="#string/hello2", I have to first manually specify hello2 it in strings.xml ?
In res/values/strings.xml
<string name="hello">Hello</string>
Then refer the string in your textview as
android:text="#string/hello"
I guess you do not have something similar to above. Hence you get resource not found exception coz the resource is not defined in strings.xml
or
You can do as below
<string name="hello_world">hello</string> // change the string in strings.xml
android:text="#string/hello_world"
For the question in the comment
You can just use
android:text="hello"
the #string bit means its a resource called hello in your xml.
So you can also add the resource to your xml if you wish. Its known to be better practice, for internationalization.

Text in XML Graphical Layout appears as strange characters

I am having issues viewing text in the graphical layout section of my android applications. This is consistently happening across many projects, new and old. See the link for visual example: http://i.imgur.com/OwENudf.jpg
The button in the image should say 'test' but instead its two boxes. Sometimes it appears as an open bracket, [
Background- I was having issues with eclipse/android sdk not creating the R.java file when a new project was created so I uninstalled the sdk and then reinstalled it. The R.java file builds fine now but the text in the graphic layouts is all strange characters.
Any idea what I can do to fix this?
The XML has one warning, which is 'Hardcoded string "test", should use #string resource"
I don't think this is the issue because I have had this error before on working applications.
EDIT:
XML code-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:text="test" />
</RelativeLayout>
I believe you are having font issues with your emulator. It can't find appropriate characters to display. You may need to reinstall that.
Ok so I searched and I think it will fix your problem (and it was too long to post it as a comment).
Go to the platforms folder where android-sdk is installed (C:\Program Files (x86)\Android\android-sdk\platforms).
Then go to the folders you're currenlty building your projects with then go to data/fonts (i.e C:\Program Files (x86)\Android\android-sdk\platforms\android-8\data\fonts) and take a look at the file fonts.xml. Also, may a ttf file disappeared when you updated your ADT (which seems odd).
You can find here an example. Read this carefully before trying to modify these files.
I hope this will solve your problem. If not, I have really no idea about what to do.

Android XML Viewer failing

I've been having this problem for a while:
Here is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/logo_text"/>
</LinearLayout>
And this what the Eclipse/Android XML viewer is giving me:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
This happens in other projects as well for seemingly random images. Project->Clean doesn't help either. I know this has to be an issue with my machine or eclipse installation because it doesn't happen on my work machine, only my home laptop.
There are no problems when the app is installed, but it would be nice to be able to see layout changes without having to install the app over and over again.
EDIT
I also get these messages anytime I use a custom View in a layout file:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
I sometimes have weird issues like this when importing new images into my project. Do you have any other res-image directories with different versions of this file? You may try removing the png and re-adding to the project.
The error message explicitly mentions the -hdpi version of the drawable directory. Have you got that image in all of the different versions of the drawable directory? Perhaps it is in res/drawable-ldpi or res/drawable-mdpi but not res/drawable-hdpi?
If you don't already have one, you could create a plain res/drawable folder and add the image there, then one would expect the system to fall back to that whenever it didn't find a definition-specific version.
Actually try to put an id tag on ImageView : android:id=:"#+id/imageView".Tell me if it is working or not.

Categories

Resources