Where are all the standard Android icon resources? - java

I have just started writing my first ever Java/Android application, so forgive the total n00b question.
How do you access the the standard operating system icons such as search icon/menu icon etc? They are not in the res/drawable folder where I would expect to find them. Are they available as part of the SDK or must you download them seperately?
EDIT
Maybe you can help me further - I am getting the following error (repeated on):
[2011-09-08 19:59:47 - TweetTab] C:\Users\Dan\workspace\TweetTab\res\menu\options_menu.xml:4: error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_menu_search').
However, the icon is not empty, the xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/search"
android:icon="#drawable/ic_menu_search"
android:title="#string/search"/>
</menu>
Am I missing something?
SOLVED
I changed android:icon="#drawable/ic_menu_search" to android:icon="#android:drawable/ic_menu_search" and it could then find the icon.

You can acces them via android.R.drawable.* or in xml by #android:drawable/something.

I installed the Android SDK for Eclipse on Windows.
Now I can find all ressources under "C:\Program Files\Android\android-sdk-windows\platforms\android-9\data\res..."

try this instead:
android:src="#android:drawable/ic_menu_camera"

it is now possible to use vector assets to generate standard (or customised) icons for android.
Add 'com.android.tools.build:gradle:1.4.0-beta3' to your build.gradle file. (The stable version will be out in the coming weeks).
Add a vector asset by right-clicking res/drawable/ > New > Vector Asset. Android Studio provides a built-in viewer for you to pick your drawable.
Reference your icon like you usually do. Eg: android:icon="#drawable/ic_help_24dp"

A lot of them can be found in android.R.drawable but not all are publicly accessible

You can find the android.R.drawable images in your local SDK folder. (Tested using Android Studio 3.0)
First have a look at the docs for the names of the drawables here: https://developer.android.com/reference/android/R.drawable.html
Second either search your drive for one of those image names.png or type in the name of any of them into your Android Studio activity and right click (goto declaration) on it to view the image. Then you can also right click that image to copy the path. Then open that folder and look at all the PNG's there.
Example on windows 10: android.R.drawable.star_big_on is located in user/AppData/Local/Android/Sdk/platforms/android-25/data/res/drawable-hdpi/star_big_on.png
(Note also on windows AppData is a hidden folder so you may need to set your windows explorer to show hidden if you are clicking to open each folder)
Also if you need to see material design icons / descriptions this is a good place to look: https://material.io/icons

Someone may see this page useful for getting those icons... http://developer.android.com/design/style/iconography.html

For those of you in the Visual Studio/Xamarin Android camp, you can view and add the standard Material icons pretty easily using the following plugin:
https://marketplace.visualstudio.com/items?itemName=nikainteristi.Materialiconsgenerator
I've used it a few times in my projects.

Related

android studio with Java compiler error: string too large to encode using UTF-8 written instead as 'STRING_TOO_LARGE'

When I clean the android project in android studio, the error happen, I have backed to previous commit or different branch, which works find couple days ago, but has this error now. I have checked this question and there is not large image or strings added for my project. STRING_TOO_LARGE String in Kothlin
I had encountered the same and fixed by clear the build cache .
I was stuck on this problem and read through this topic and no one provided a future solution. I did NOT want to revert back my Gradle. Therefore, here is the link to the updated dependencies https://github.com/stripe/stripe-android. Look for the "Android Studio (or Gradle)" section and you should see this "implementation 'com.stripe:stripe-android:8.1.0'" also you might need to add "-keep class com.stripe.android.** { *; }" if you are enabling minification in your build.gradle file.
Overall Stripe has stopped updating their own "Stripe docs" which can be found here. To give them credit their docs are helpful and should be read at least once, but be mindful that most of the docs are out date when I wrote this...
Hope this helps :)
You can use AAPT (from the android sdk/build-tools) to examine the APK and look for the offending string with the following command line (Linux):
// Linux/Mac
./aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE'
// Windows
aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE'
Which should point you to the culprit. In my case it was:
resource 0x7f0f015a com.example.app:string/eula: t=0x03 d=0x00000f10 (s=0x0008 r=0x00)
(string8) "STRING_TOO_LARGE"
For the time being, you can downgrade Gradle version to resolve this issue.
Use gradle 3.1 version like 3.1.3 below.
classpath 'com.android.tools.build:gradle:3.1.3'
It happens that I had an SVG too long (90Kb). So I've opened de SVG in Adobe illustrator, simplified the path to a significant number of vector less so the new icon weight 3Kb and, finally, imported again in Android Studio.
You can have a look at your Project in Android Studio and watch if your SVG drawables are larger than needed for an icon.
just use <?xml version="1.0" encoding="utf-8"?> before in your drawable file.
Example:
<?xml version="1.0" encoding="utf-8"?>
<vector
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="490.282"
android:viewportWidth="490.282"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#fff"
android:pathData="M0.043,245.197c0.6,10.1 7.3,18.6 17,21.5l179.6,54.3l6.6,123.8c0.3,4.9 3.6,9.2 8.3,10.8c1.3,0.5 2.7,0.7 4,0.7c3.5,0 6.8,-1.4 9.2,-4.1l63.5,-70.3l90,62.3c4,2.8 8.7,4.3 13.6,4.3c11.3,0 21.1,-8 23.5,-19.2l74.7,-380.7c0.9,-4.4 -0.8,-9 -4.2,-11.8c-3.5,-2.9 -8.2,-3.6 -12.4,-1.9l-459,186.8C5.143,225.897 -0.557,235.097 0.043,245.197zM226.043,414.097l-4.1,-78.1l46,31.8L226.043,414.097zM391.443,423.597l-163.8,-113.4l229.7,-222.2L391.443,423.597zM432.143,78.197l-227.1,219.7l-179.4,-54.2L432.143,78.197z"/>
</vector>
None of the above solutions worked for me. What ended up being the cause of the problem was, as it states, a String that was too large. Specifically, in my arrays.xml file under the values directory, I had some SVG arrays that were used within my app and commenting them out solved the issue.
If you know for certain you have some longer Strings somewhere in your resource directories (/res), check for any large Strings that may be lurking.
Also, this solution may help others but was not linked to in this thread.
I've been hunting for the source of STRING_TOO_LARGE errors in our build for a long time and none of these solutions worked. The reason none of them worked was that I had progaurd turned on in debug builds so when the string was replaced it didn't end up in the apk. When i disabled progaurd for debug builds, built the apk and then decompiled with apktool as suggested elsewhere
java -jar apktool_2.4.1.jar d debug.apk
and found the xml file that was in another library but progaurd stripped out before:
grep -r "STRING_TOO_LARGE" ./debug
Hope that helps someone
I found an SVG file that had a very long pathData. I commented it out and the error went away. That very same vector (when called) at runtime would cause a crash (before it was commented out).
clear your gradle in windows
gradlew cleanBuildCache
in mac
./gradlew cleanBuildCache
then building you apk if your project has problem it will be show you in the 'Messages'
view. location your problem and fix it. run agent.
The issue is caused by the AAPT/AAPT2 (Android Asset Packaging Tool) which processes your app’s resources and replaces them with the STRING_TOO_LARGE value when it finds a large string.
Find out for which one cause this problem.
To find out follow below steps:
A. Best Way:
Generate build APK
Decompile APK using any decompiler and download it.
Open it in any editor(Ex. VS Code)
Then search "STRING_TOO_LARGE" text globally and you will find affected files.
B. Another Way
The simplest way to find out, Builds an APK and analyze it. Select Build > Build Bundle(s) / APK(s) > Build APK(s). When the build completes, a confirmation notification appears, providing a link to the APK file and a link to analyze it in the APK Analyzer.
If you take a look into the the vector drawable file affected by this issue, you will find something like this:
I found this solution from Here
Just use gradlew cleanBuildCache in your Android studio terminal
In my case, i deleted a view from xml but forgot to remove its references in my kotlin code. Make sure to check this before doing anything fancy.
I found the answer from a duplicate question for Kotlin from here
Add <?xml version="1.0" encoding="utf-8"?> to the top of any resource .xml file that is missing it. (check your layout xml files, specially)
For me "gradlew cleanBuildCache" did not work, and running aapt dump --values resources MyAppName-regular-debug.apk | grep -B 1 'STRING_TOO_LARGE' did nothing either...
I ended up just deleting all my vector images since they were all pretty large and that fixed my build.. So I guess I'll have to add those back in a way that does not throw the error again..
In my case, I had renamed the package and the output-metadata.json contained the old package name. Renamed the package name there, and it was fixed.
In my case, the problem was due to the following lines in the manifest:
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"/>
Once I deleted them, the build went fine.
In my case I declared a string variable in xml using data binding without assigning a value to it. by setting value to variable problem resolved
Windows 10 Solution
Finding the file with the error: use a online decompiler if it's not a problem is some one else sees your code. Download .zip file. Open up notepad++ search -> Find in files -> STRING_TOO_LARGE -> Find all.
If the problem file is a vector asset:
Vikasdeep Singh has a great solution: avocado. Avocado will make the vector file smaller.
I had this problem and clearing the cache or updating the Gradle plugin version was not a solution
To solve the problem I had to change the name of the longest XML file to make it a bit shorter, and right after doing that the problem was solved.
In my case I use Invalidate cache and restore
go to file/Invalidate cache and restore
instead of this
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
Replaced it with this in the gradle.properties
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=STRING_TOO_LARGE

How to use SceneBuilder's DarkTheme in my application

Firstly, is it legal to use the dark theme of JavaFX's SceneBuilder 2 in my application? Since it is open source now here: SceneBuilder/css
Secondly, how to do this if legal? Or just for training purposes if not legal?
I tried to download the ThemeDark.css file from the link above and add it to my fxml file, but i see no change applied.
Any ideas ?
Edit (what I did):
I have downloaded the .css file and pasted it in package css.
Then I added these lines in my .fxml file (with the <> symbols but I removed them in this question as they hid the text if present) :
stylesheets
URL value="#/css/ThemeDark.css"
/stylesheets
See below resulting screenshot: (themeDark not applied)
If you are using SceneBuilder you can add a global css sheet to it and be happy with the new look.
Alternative, if you want to set it within your code you can use
scene.getStylesheets().clear();
scene.getStylesheets().add("path/stylesheet.css"); // Modify to your path
to add a style-sheet. Notice that you should put your style-sheet in a resource folder in your application, just to keep everything cleaned up.

Where is the R.java file in Android Studio?

Where is the R.java file in Android Studio? Can someone please help with this? I already tried google for the answer but can't find any solution.
Based on the new stable release of Android Studio (3.6) we have:
So, now to find your generated resource classes you need the following steps:
1) Open your project.
2) Go to your module build path.
3) Open the outputs/apk/debug/app-name-debug.apk file.
4) Choose your classes.dex file.
5) Look at the down placed area and go to your full package path.
6) You can see all bytecoded resource classes. So, scroll down to what you are looking for.
7) Expand the resource class you need to proceed (for example, let it be R.id)
8) Go to you id's.
That's it.
UPDATE:
If you would like to see actual id integer number you should follows steps below:
1) By (7) Go to the resource class you need to proceed and right click to show the context menu
2) Choose "Show Bytecode" to see the flexible dialog "DEX Byte Code for R$id", for example, for id class
3) Scroll down to the actual id to look its number
Although the current Android Gradle Plugin doesn't generate a R.java anymore you can still inspect the corresponding class file (see Sergey V.`s answer).
However, if you (like probably in most cases) just want to look up the generated IDs for your resources, there is an easier way:
In the project pane on the left hand side switch from Android to Project view using the drop-down at the top. Then navigate to app/build/intermediates/runtime_symbol_list/<insert build type here>/R.txt. This file lists all IDs generated by AGP during the build process.
I use Android Studio 3.3.2
\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\android\support\constraint\R.java
As noted above, "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file".
Using the ubuntudroid solution you can find an id also this way. Find R.txt and copy absolute path. Project > app > build > intermediates > runtime_symbol_list > debug > R.txt. Then right click and select Copy Path..., 1. Absolute Path Ctrl+Shift+C.
This way you will obtain a path to R.txt, for instance, "C:\Users\user\AndroidStudioProjects\your_project\app\build\intermediates\runtime_symbol_list\debug\R.txt". Copy the path without R.txt to a text file for future references, for example, with Notepad++.
Press Ctrl+Shift+F to find in directory. Insert an id and the path.
== Old answer ==
Change a project view from Android to Project or Project Files. Find one of these two files.
Then you can revert back to Android view.
I use Android Studio 2.3.3. The R.java file is shown in the picture above.
In the left upper side, there is a select list. Select the [project] option so that you can see all the folders and files.
R.java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.
./app/build/generated/source/r/debug/android/support/v7/appcompat/R.java
./app/build/generated/source/r/debug/your/packagename/name/R.java
I am using Android Studio 2.2.3 , the R.java file is shown in the picture below.
Goto in the left upper side there is a selecting list ,
select [package]
Open "App Folder"
com.example.saeedanwar.myapplication;
r
In my project in Android Studio 4.1
R.jar that you can actually unzip resides in app build folder, as follows:
jar -xf R.jar
Once the jar is unpacked you can find R.java inside of app package:
If you're using Mac or Linux, try the following command line on your terminal:
find . -name "R.*"
It will print something like:
./app/build/intermediaries/runtime_symbol_list/debug/R.txt
./app/build/intermediaries/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar
It is inside app\build\generated\source\r folder
Project/app/build/generated/source/r/debug/com.android.'projectname'/R.java
--The R.Java that contains your xml layouts and views id's in Android Studio 3.5.3 -- Project/app/build/generated/not_namespaced_r_class_sources/debug/r/com/"your package"/R.java
This answer will be in a constant state of flux until Android standardize a method of matching their annoying decimal/hexadecimal id references to a tangible resource such as my_layout.xml.
For Android Studio Dolphin | 2021.3.1 Patch 1 have a look at this file:
/project/package/build/intermediates/stable_resource_ids_file/debug/stableIds.txt
It is produced by RUN (not just BUILD). Sample:
layout/mtrl_picker_header_fullscreen = 0x7f0d00de
string/cancel = 0x7f1101f0
style/ThemeOverlay.MaterialComponents.MaterialCalendar = 0x7f1202f3
id/gpxBtn = 0x7f0a0346

values-21, values-22 or values-xx folder is gone after Android Studio 1.0

When I create a new project with API14 as minimum, then there is no values-21 or values-22 folder in my project. I don't see any styles.XML anywhere, so how should I put in XML code for just Lollipop?
I use Android Studio 1.0.1, and I have SDK 21, 21.1.1, 24.0.2 installed.
Updated: Since API 22 has been released. API 23 is the same idea.
Right click the RES folder
Then type values-v22 as the directory name and choose xml as the resource type.
If you do NOT see the values-v22 show up, click the Project pulldown at the top of the screen like so. e.g. Change from Android to Project
Now right click styles.xml in the values folder and choose copy
Now right click the values-v22 folder and click paste.
You should see this popup
Click ok
At this point you should be good to go.
It is just a bug! Anyway I find a way to get it back:
Write anything in styles.xml that is related to new material theme
example: <item name="android:colorPrimary">#color/colorPrimary</item>
It will show you an error hover over it and press Alt+Enter.
choose the first choice Override Resource in values-v21.
I know it isn't the best way to do that, but it works until anyone can find a better way.
Try to switch from Android to [![Project][1]][1] as shown below

Missing id class in R.java

I am developing an Android app using Phonegap and jQueryMobile, working in Eclipse. I want the app, with the user's permission, to auto-install a launcher icon on the user's "desktop". I've found the example LauncherShortcuts.java on Android Developers, and I am almost to the point of getting it to work. That's a big achievement, since I know extremely little of Java programming.
Almost.
This is the example code online:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html
One string or thingy in the code refuses to cooperate. Line 83...
TextView intentInfo = (TextView) findViewById(R.id.txt_shortcut_intent);
...has this constant or variable in it called "R.id.txt_shortcut_intent", and Eclipse says it doesn't recognize the id part. If I follow its suggestion of adding a class 'id' in R., it tells me there is no field txt_shortcut_intent in 'R.id'. That doesn't surprise me.
I've been able to fix a few similar errors involving R.something_or_other. But not this one. My R.java only contains the classes attr,drawable,layout, and string.
What is going on here and most importantly, what should I do to get this thing up and running? The launcher icon is all that stands between here and actually launching the app (how ironic).
If you find any errors in the project. Sometimes id of R.java entries will be shifted to string folder or R.java.
For this choose
project → clean
file → close all
click on your project
See the entries in id of R.java your ids will be in this folder
An android app uses an xml to define the layout of all the elements you want to display. In this case, you're missing an element that displays text called TextView. You don't have the Textview 'txt_shortcut_intent' defined in the xml, probably.
Here's the xml you're looking for (just copy and paste it into your main.xml):
http://developer.android.com/resources/samples/ApiDemos/res/layout/launcher_shortcuts.html
The ADT Plugin in Eclipse can only rebuild the R class if there are no (Java) errors.
Therefore, fix all errors and check if your layout ressource has the correct id (txt_shortcut_intent).
It's worth a try to clean the project and restart Eclipse.

Categories

Resources