Appropriate Paths for Resources in AndroidManifest.xml - android

in my AndroidManifest.xml, I have
<application
android:icon="#drawable/iC_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And when I run gradle build, I keep getting the errors
resource drawable/ic_launcher (aka com.example.MyProject:drawable/ic_launcher) not found
resource string/app_name (aka com.example.MyProject:string/app_name) not found
resource style/AppTheme (aka com.example.MyProject:style/AppTheme) not found
I'm guessing that the #drawable #string and #style correspond to the directories with the same names I've seen before when I used Android Studio. But now that I don't use Android Studio anymore, where should I put them?
Currently my Java files are located in
app/src/main/java/MyProject
and my AndroidManifest.xml file is located in
app/src/main/AndroidManifest.xml
The directories are generated via gradle init; do I need to rearrange them?

I'm guessing that the #drawable #string and #style correspond to the directories with the same names I've seen before when I used Android Studio
There is no style directory and there is no string directory. Style and string resources go in a values directory.
But now that I don't use Android Studio anymore, where should I put them?
The same place that Android Studio puts them, and the same place that they are in any Android project. For a module named app and a source set named main, you would create subdirectories under app/src/main/res for different resource types and resource sets.
FWIW, this free book of mine explains all of this.

Related

Android/Gradle: Why is it possible to declare several times the values.XML file?

Pre-requisites
I have created an application in which the following tree structure is used (the app-level build.gradle being modified according to the documentation - you can find these changes at the end of this question):
app
src
main
my_theme
bundles
a_bundle
drawable folder, values folder, layout folder, etc.
global
drawable folder, values folder, layout folder, etc.
There are several bundles. All the values directories (one per bundle and one in the global folder) contain the file strings.XML. My application does compile and execute correctly.
However, the Android documentation states that:
Note: If two or more resource directories contain the same resource file, an error occurs during resource merging.
(https://developer.android.com/studio/write/add-resources#change_your_resource_directory)
Question
So, since I use the same file strings.xml , why no error is shown? (of course, the content of these strings.xml files changes according to the directory in which they are located - either their bundle directory, or the global directory)
app-level build.gradle
To make it work (eg. to make the Android Resolver able to resolve symbols), I added these lines:
android {
sourceSets {
main {
res.srcDirs = [
'src/main/bestheme/global',
'src/main/bestheme/bundles/a_bundle'
]
}
}
}
strings.xml (and any values resources) are different in the sense that resource identifiers are not based on file names but are actually specified inside the files.
Resource merging occurs on resource identifier level. If there are no conflicts in resource identifiers on the same sourceset level, then the merger works all right.
The documentation notes are valid for resource types where resource id is derived from the filename. For example, layout or drawable resources.

Strings resource file triggers "Namespace is not bound" when using build flavors

If I take a project (apparently any project, in my experience at least), create a new flavor build variant, and copy the whole strings.xml file from the main/res source folder to the flavor's res folder, the build shows the "Namespace is not bound" error relating to the flavor's strings.xml file which is obviously exactly the same as the one in the main source folder. Android Lint does not show a warning for the main/res strings.xml.
In reality my project has a much smaller strings.xml file in the flavour res folder, but it still shows this Android Lint warning.
Is this a bug in Android Lint, or is there a real issue here and if so how do I correct it or suppress it if it's a false positive? Which namespace? Not bound to what?
I looked at the Android Lint checks documentation to see if there was more information about this Lint check but oddly it does not appear to be on the list of Lint checks: https://sites.google.com/a/android.com/tools/tips/lint-checks

Invalid resource directory name in android

I am using android studio, I added gms library in my android project. And after build I got error
Error:Execution failed for task ':app:mergeDebugResources'.
> D:\Android\Mejodo\app\src\main\res\values-11: Error: Invalid resource directory name
I read in other articles that, these folders are for different screen sizes. But I have only three values folders (values, values-11, values-v11), So >=11 version handle with values-11 folder.
But I don't know how to solve it.
Can I delete these folders ?
Please suggest something.
v11 in values-v11 is a qualifier for Android sdk version v11.
Take a look at http://developer.android.com/guide/topics/resources/providing-resources.html.
So I think "values-11" folder is unnecessary and wrong.
Delete all unnecessary folder containing empty folder
Like above "values-11" folder is unnecessary so delete it
After that clean the project.
I had the same error. Indeed values-11 is not a valid name, instead it has to be replaced by values-v11 in order to compile. So basically I would suggest to move anything you had in folder values-11 and move it into the values-v11 one.

Making subfolders in a resource folder

Is it possible to make subfolders in the resource folders in the Android project? I have about 200 images (thumbnails) that I need in my project and I could add them in the drawable-mdpi, but it would be better to not mix these images with the other ones. Something like drawable-mdpi --> thumbs --> all images here.
No this is not allowed. You are only allowed to make folders specified by the android documentation.
The allowed sub folder names are specified in the link. Android generates the R.java based on these structures and putting sub folders can cause errors.
actually, there are mechanisms in place that allow the R.java file to be generated when there are folders with non-standard names in the res folder.
(i ran into this wanting to share a git repo as a submodule of both an iOS and Android project, but not wantint the Android project to pick up files that resided in a folder i designated.)
aapt is the tool that creates the R.java file, and it can be invoked with the --ignore-assets argument. there is a set of defaults for this found in the google source documentation, or a less verbose description simply by invoking aapt from the command-line without any arguments (or --help, which isn't a valid argument, but presents help nevertheless). using the line aapt.ignore.assets=xxx in an ant.properties file in your Android project will accomplish pretty much the same thing, depending upon your needs or preferences.
if you do not have a build.xml or other mechanism that forces usage of ant (which i do not), one of the aapt --ignore-assets defaults is <dir>_*, which means ignore any folders starting with _.
this was my fallback: i created a directory called _iOS_retina and placed all of my #2x files in there. (in Xcode, i can simply pull in resources from wherever they reside). the default invocation of aapt simply ignores it. to further streamline my project, i also updated my .project file to contain a resource filter that ignores this folder, and thus it doesn't take any space in my eclipse environment, either.
<filteredResources>
<filter>
<id>1371429105277</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-_iOS_retina</arguments>
</matcher>
</filter>
</filteredResources>

Uploading MonoDroid app to Android Market

I am trying to load an app to the Android Market. Below are the instructions I am using from the following website to prepare my application for submission:
http://android.xamarin.com/Documentation/Guides/Preparing_Package_for_Android_Marketplace
This following message is at the beginning of the instructions. But no instructions on how to add this to the AndroidManifest.xml file.
In order for the Android Market to accept your application, it must
define an application level icon. Ensure a line like this
exists in your AndroidManifest.xml:
<application android:label="MyApplication" android:icon="#drawable/icon">
A future release will provide better support for setting this.
The very first item has me stumped because I am getting the following error when I try to upload my application to the Market.
"The icon path specified by the manifest is not in the apk."
My question is, how do I add the application level icon statement to the manifest file?
Thanks.
p.s. The app deploys to both the emulator and local Android device in debug and release modes with no errors.
You can add a manifest file to your project by bringing up the property pages for your project, going to the Android Manifest tab, and doing the 'add AndroidManifest.xml' link.
Now there should be a file called "AndroidManifest.xml" in the Properties folder in your project.
Add the line specified to this file, replacing any existing element.
I had the same issue and it had nothing to do with the icon. I had an application class (GlobalVars extends Applications) and this was defined in the manifest as different: <application android:name=".GlobalVars" /> I deleted this and added android:name="com.example.myapp.GlobalVars" to the application declaration.
If it is the icon you may have drawable-hdpi, -ldpi, -mdpi folders, and no drawable folder. Or have a drawable folder but the icon is not in it.
Can you post the relevant snippet from your AndroidManifest.xml file? Whatever you have as the android:icon attribute ("#drawable/icon" in the example) is what the apk will be looking for. You can set this manually in the xml file, or by using the wizard in the ADT plugin for Eclipse. If this is set correctly, this means you should have a file called icon.png in one of your drawable folders. If you don't have an icon.png, can you post your folder structure?
In an app I've uploaded to the market, I have the same attribute - #drawable/icon - in my manifest, and therefore I am required to have a file called icon.png in my project. In my case, I have three different icon.png files in my various density-based drawable folders (res/drawable-hdpi, res/drawable-mdpi, res/drawable-ldpi). In your case, you need to at least have res/drawable/icon.png.
This error can also be generated if the manifest xml includes more than one < application > node.

Categories

Resources