Just to give a bit of clarity on what files exactly to edit.
What is the problem?
Android isn’t building properly because of the error message saying unbound prefix
on the line that uses the android
namespace.
What’s an example of the line that uses the namespace?
In my case, it was:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Whatever case it is, the problem can be resolved by adding the following namespace to the topmost XML tag (for the Android platform, it is the <widget>
tag):
xmlns:android="http://schemas.android.com/apk/res/android"
That will turn your top most XML tag into the following:
<widget id="com.your.app" version="0.0.5" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android">
Why does it keep erroring after I’ve done this?
It still keeps erroring because you might have edited the platforms/android/app/src/main/res/xml/config.xml
, which is an automatically generated file.
This means that whenever you tell ionic to build your android app (using ionic cordova build android
), it will re-generate the files, thus removing your changes.
Which file should I edit then, to include these changes?
You should edit the root_project_folder/config.xml
file.
Find the <widget>
tag on that config.xml file. It should be at the top most part of the config.xml
file.
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.your.app" version="0.0.5">
<name>Your App</name>
<description>Your Application</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">Your Team
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="ScrollEnabled" value="false" />
<preference name="android-minSdkVersion" value="19" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<platform name="android">
<allow-intent href="market:*" />
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
// ... etc
The Fix
Add the namespace to the widget tag in root_project_folder/config.xml
.
It should look like this:
<widget id="com.your.app" version="0.0.5" xmlns:android="http://schemas.android.com/apk/res/android">
Once you’ve done this, running
ionic cordova build android
will allow your auto-generated files to contain your android namespace, thus building successfully.
My ionic info
details
Ionic:
ionic (Ionic CLI) : 4.10.3
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.2
Capacitor:
capacitor (Capacitor CLI) : 1.0.0-beta.19
@capacitor/core : 1.0.0-beta.19
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4, browser 5.0.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 19 other plugins)
System:
ios-deploy : 1.9.4
ios-sim : 8.0.0
NodeJS : v10.12.0 (/usr/local/Cellar/node/10.12.0/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.2 Build version 10E125