I have finished to write my small program and now I want to add locale.
Before I had next structure: /res/value/strings.xml
I have added to the structure new folder with file with another language:
/res/value-uk/strings.xml (it's ukrainian language)
after that I built my APK in AndroidStudio and I got error:
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
Unknown failure (Failure)
Error while Installing APK
I was searching this problem in google and nothing helped me.
Please reccomend me how to solve this problem. Thank you.
I had the same problem and I found a lot of people managed to solve the problem by adding the full package name inside the various manifest "android:name".
It didn't work for me and I found out that my problem was different:
I had two string files, "strings.xml" and "strings-en.xml. In the former one I had some values with the field "translatable=false", such as:
<string name="db_name" translatable="false">my_db</string>
To solve the problem I had to REMOVE that string resource from the strings-en.xml, in order to have those strings only in the default strings.xml.
I hope this can help future developers.
The xliff namespace declaration in your strings.xml file seems to be wrong. Try using <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> instead. Or strip out all the <xliff:g> tags and see if it makes a difference - they are not needed any more after translation. And Chol is right: the default folder name for Ukrainian is values-uk, not value-uk.
Related
Here is my values\strings.xml (the default file) and everything is self explanatory:
My question(s):
How can it be "not found in default locale" if I am editing the default locale (values\strings.xml)?
How can it be a lint translation error if I set translatable="false"? In the values-pl\strings.xml (and values-ru, values-iw folders as well) the strings don't exist even? it shouldn't anyway.
I can't seem to understand why I don't get the error for the Russian string.
(I would show the values-ru\string.xml or values-pl\string.xml here but there is nothing there of interest, since the strings are missing anyway...)
this happened to me too
I do 2 things:
Verify entire file to see another translate not done ( I have ones in file en but in pt-br)
Clean, update gradle and quit and restart the Android Studio
Rebuilding can take a long time. YMMV, but...
Simply remove the offending line and re-add it.
Worked for me. Very fast.
In my case this helped me:
Select the strings that cause error.
Cut them.
Paste them again
If it doesn't work for you, try adding the same strings to strings.xml(v21) file.
Press Invalidate Caches / Restart ... to restart android studio. It worked for me. Actually this happened when I had copied files from my other computer and pasted via file explorer.
I solved this issue by following below steps:
cleaning my project
rebuilding it
and finally pressing invalid caches/ Restart in file menu
If you just Clean Project it probably works. It worked for me.
I had the same error message, just with the weird issue that it was thrown in the default locale itself and all translations. Turns out you should not use dots in your name (e.g. name="bla.blub") because it will be internally converted to "bla_blub" and then it cannot match with "bla.blub", hence the error.
I only had to change the dots to underlines in the default locale and then all other errors in other translations (including dots in the name) were gone as well.
But be aware that other build tools can still create issues, so replace all the dots with underlines instead!
Quitting Android Studio and restarting it fixed it for me.
You simply just have to copy the offending line (or just one of the multiple of offending lines), remove it, and re-paste it. That removed the issue for me.
Just make sure that you have same naming conventions on all strings files including the same capitalization.
let's say if you have "sign_in" in strings.xml and "sign_In" in your fr/string.xml, so it will give you error on fr/strings.xml like "is translated here but not found in default locale". So, when you edit to "sign_in". The error will remove.
I was having this problem for all the strings in my xml file.
The thing is, your default strings.xml shouldn't have a tools:locale attribute as the other translated files have. If it does, whenever I compile the app in release mode, it treats it as another translated file.
I've created a tool to manage the translation status of android apps.
It not only tells you what strings are missing on the other languages, but it can also report, and clean the left over strings that you may have deleted on your default translation file.
https://github.com/gubatron/android-missing-strings
To clean all left overs in other languages invoke like this
./ams --cleanleftovers -o all.txt
This will clean the left over strings and it will output the missing strings report for all the languages into the all.txt file
Copy and paste didn't work for me.
I also tried Clean and restart, the previous error was gone but new entered strings still have new errors occur.
I tried closing the opened strings.xml file and Translations Editor, then restart.
strings.xml file and Translations Editor
That works for me.
Well, in my case, this happened when there was a format error with the previous string of the string that's being reported. Unfortuantely that format error was not reported. Correcting the format error solves the issue.
Add this,It will work
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ExtraTranslation">
Press double shift for open Translations Error and then check and uncheck in Untranslatable column the item with error.
I have been reading about ignoring hardcoded string from Log:
Log.d(TAG, "onBindViewHolder: ");
Even inside a Toast:
Toast.makeText(context,"Hardcoded text",LENGTH_SHORT).show();
Sources:
How can I find all RELEVANT hard coded strings in Android Studio?
Android find all hardcoded strings in code using Android Studio
In the first source there is the best approach but somthing is not working and that is:
"adding #SuppressLint("HardcodedNonLog") to the top of the class definition"
Is there a way to ignoring these kind of hardcoded strings?
UPDATE
Create a Gradle task to add "//NON-NLS" to every Log, could be a good way? If the answer is yes, how could I do that?
Yes, you can!
At least with Android Studio 3.0 canary 9 (not checked with previous version).
There is option like "Annotate class 'Log' as #Non_Nls"
After that will be generated file at path "$modulename/android/util/annotations.xml" with this content:
<root>
<item name='android.util.Log'>
<annotation name='org.jetbrains.annotations.NonNls'/>
</item>
</root>
With this file all strings mentioned in Log will be ignored for this module.
Hardcoded text is not an error it is a warning which can be dealt with by pressing left alt+ Enter. When you press alt+Enter you are just defining that hardcoded string to string.xml in values folder.
I learn android with sample apps from textbook. In the given sample source R.string.something is recognized:
However, in my own EXACT source code, same R.strings are not recognized- highlighted as errors:
Does anyone know how to fix it?
I've had this many time with eclipse, and it was not a setup / code problem on my side. Generally, cleaning, rebuilding and sometime even stopping and restarting eclipse solved it. And yes, it's a pain in the neck ...
Try a clean of your project, if that does nothing then click on the problems tab and see if there's any build related issues, you may be missing a required jar or something!
These are following reason possible.
1-: You import android.R;
2-: Any error in xml files.
3-: Please check you String.xml file may be any error or declare a string more then two time.
I assume you are new to Android.
If so, there are two ways of using text strings in Buttons, textviews and so on:
1) Hardcoded string - you put the text you want in quotation marks (""), for example:
yourTextview.setText("Hardcoded string");
2) You can call the text from your String resources (res/values/strings.xml).
That is a much better approach seeing is is easier to translate, make changes and so on.
In your strings.xml file you can create all your string values, and call them from there.
Like in you example, if in your strings.xml file you have for example:
<string name="delete">This is String resource</string>
you can then call the string from there, like so :
yourTextview.setText(R.string.delete);
Hope this helps!
Consider following project hierarchy
Base
Common
Flix
We have Base and Common as library project which we are using in several other projects like Flix. We would like to define some sort of property file into Base and Common project and would like to refer the properties defined at Base or Common level into string.xml file of Flix project.
For example
Consider we have a property file named base.properties under "Base/assets" folder with following content
app.props.cms.url=http://test.flixv2.dev.com/api
We have string.xml file into Flix project, where we have a string resource
<string name="cms_url">HERE WE WOULD LIKE TO REFER THE PROPERTY</string>
we have tried following which is not working
<string name="cms_url">${app.props.cms.url}</string>
Please let know your views.
Thanks
Are you using any kind of build system like Maven or Gradle? This seems to me like a dependency thing.
There is another way out, which is not exact solution of my question
Ref: Concatenate multiple strings in XML?
we tried following:
created a string resource in Base project as below
<string name="app.props.cms.url">http://test.popcornflixv2.device.screenmedia.net/api/</string>
And refer the same into Flix project as shown below:
<string name="cmsservice_url">#string/app.props.cms.url</string>
There seems to be a suggestion that the "official way" of doing this (where you insert the package name prefix) does not work. However, this is a very old report, so I would try that first, before the "reflection" approach - both of which are described here:
android import ressources from library project
In my app I put a certain link in strings.xml file and then I use it in the rest of the application. Here is the way I put in strings.xml file :
<string name="link">http://mylink/</string>
and here in how I get it in my activity :
String link = getResources().getString(R.string.link);
The problem is that this String returns sometimes not the value from strings file. I get often #ff666666 and that's strange. Why sometimes it works fine and sometimes not ?
Has anyone any idea about this?
Thanks in advance.
You need to Clean and Build again before running the project.
This is happening because some times new values are added in the R.java file that doesn't get updated, so you need to clean to force the R.java file to refresh and update itself.
Try debugging into the particular method and inspect the value of R.string.link. Is it the same as you would see in the R.java file? Sometimes you get this problem when shifting around stuff in your resource files. "Project->Clean...->Clean all projects" in Eclipse usually solves it.
It is working fine. Just now i checked with following lines. Make sure sure to clean your project and build it.
<string name="link">http://www.google.com</string>
String name = getResources().getString(R.string.link);
Log.e("Name is:",name);