By the design with CLI 4.1.0 the structure of Android resource folder is as follows:
_Android/src/main/res/values_
By default in values folder there is colors.xml and styles.xml files.
When, I add a strings/xml file it will cause the app build to crash.
The reaons: the strings.xml is created during build and if a custom file is introduced it will replace the content of the default one causing two string to be missing (whic are used in AndoridManifes)
Error log
D:\git\NS-Issues-2018-II\NativeScript\issue-5897\platforms\android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:33: AAPT: error: resource string/app_name (aka org.nativescript.issue5897:string/app_name) not found.
D:\git\NS-Issues-2018-II\NativeScript\issue-5897\platforms\android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:44: AAPT: error: resource string/title_activity_kimera (aka org.nativescript.issue5897:string/title_activity_kimera) not found.
Reproducible with hello world template and CLI 4.1.0 on Win.
Steps to reporduce:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="nativescript_google_maps_api_key">Some-Api-Key</string>
</resources>
title_activity_kimera and app_name@NickIliev when you place anything in the <project dir>/app/App_Resources/Android/src/main/res it automatically replaces the default resource that would have been used for the build. This is by design and allows the user to fully override the resource.
I agree that the current case leads to unexpected errors during build, but it can be easily fixed by adding the following lines in your strings.xml:
<string name="app_name">__NAME__</string>
<string name="title_activity_kimera">__TITLE_ACTIVITY__</string>
NOTE: CLI will replace these placeholders directly in your <project dir>/platforms/android once it builds the application.
Can you give it a try and inform us if it works for you?
Yep, it works when we add the two string manually. Currently, our templates are not shipping those strings and they are added build time so that would break anyone who decides to introduce their own strings.xml(pretty common technique).
We should either change all of our templates (to include a string.xml with the placeholders by default) or add/merge them if a strings.xml is created by the user (cognitive CLI). As the majority of users are not aware what these placeholders are meant for, I would think the second approach is better.
Reopening this issue as it seems that all users which are using localizaiton plugin are overwriting the strings.xml file which will cause the issue to crash the app if no title_activity_kimera is explicitly provided in the newly introduced strings.xml file.
Just experienced this when I created a strings.xml that only had the __app_name__ declared. The build failed because title_activity_kimera couldn't be found. After reverting my changes the build still failed though, so I just removed the label attribute from activity to fix.
installing https://github.com/EddyVerbruggen/nativescript-localize caused this error for me.
Most helpful comment
@NickIliev when you place anything in the
<project dir>/app/App_Resources/Android/src/main/resit automatically replaces the default resource that would have been used for the build. This is by design and allows the user to fully override the resource.I agree that the current case leads to unexpected errors during build, but it can be easily fixed by adding the following lines in your strings.xml:
NOTE: CLI will replace these placeholders directly in your
<project dir>/platforms/androidonce it builds the application.Can you give it a try and inform us if it works for you?