I'm trying to add a specific android platform.
Now all answers to these same questions look approximately the same:
Add
<preference name="android-targetSdkVersion" value="XX" /> to your config.xml
So, I tried:
Adding that line to my config.xml where XX = 23
cordova platform remove android --save
ionic cordova platform add android --save
My output shows me:
Using cordova-fetch for cordova-android#~6.2.2
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.ionicframework.someapp
Name: MyApp
Activity: MainActivity
Android target: android-25
This looks like it's using android-25.
My myapp/platforms/android/AppManifest.xml looks like this:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.ionicframework.someapp" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="#mipmap/icon" android:label="#string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/provider_paths" />
</provider>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
But my platforms/android/project.properties just shows target=android-25
So. How can I configure my android version to use android-23, eventually manually if there's no straight answer.
(I had this issue before and I believe I resolved it back then by reverting to a 5.X.X build of cordova. New requirements make that kind of impossible this time)
I'm not sure if this is exactly what you're looking for, but this might help. If you are trying to only use a certain API level / android version, you can use the command on cli:
cordova platform add android#[cordova android version]
ie: cordova platform add android#4.1.1
You can check out the documentation on which versions of cordova android support which API level.
Note:
Please note that the versions listed here are for Cordova's Android package, cordova-android, and not for the Cordova CLI. To determine what version of Cordova's Android package is installed in your Cordova project, run the command cordova platform ls in the directory that holds your project.
Struggle with the same problem. Is there a final solution for this problem?
This seems to be ignored in the config.xml:
<preference name="android-minSdkVersion" value="16"/>
<preference name="android-targetSdkVersion" value="23"/>
"cordova platforms add android" always install android version 6.2.2
Related
I'm using v3.7.0 and I want to change the AndroidManifest.xml when I build my app. Currently I have tried changing the my-project-path/config.xml file adding the the following lines:
Option a.
<widget>
<preference name="android-manifest/application/activity/#android:windowSoftInputMode" value="adjustPan" />
</widget>
Option b.
<widget>
<preference name="android-windowSoftInputMode" value="adjustPan" />
</widget>
Then I do:
$ ionic cordova build android
And I was expecting the following change on my-project-path/platform/android/AndroidManifest.xml:
<manifest>
<application>
<activity android:windowSoftInputMode="adjustPan">
</activity>
</application>
</manifest>
But I get the same result as without adding the preference settings:
<manifest>
<application>
<activity android:windowSoftInputMode="adjustResize">
</activity>
</application>
</manifest>
How can I apply the desired effect to the AndroidManifest.xml?
Thanks!
I found how to do it. If your Cordova version is above 6.4.0 you can use the tag <edit-config> (http://cordova.apache.org/docs/en/7.x/plugin_ref/spec.html#edit-config) and I think that if you are using the latest version of Ionic probably you'll have a Cordova version above 6.4.0 (I have 7.1).
So the way to make the desired change that I wanted I had to set the my-project-path/config.xml file as follows:
<widget xmlns:android="http://schemas.android.com/apk/res/android">
<platform name="android">
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:windowSoftInputMode="adjustPan" />
</edit-config>
</platform>
</widget>
Check that the widget has a new attribute.
With this change when I build the Android version the manifest my-project-path/platform/android/AndroidManifest.xml looks like this:
<manifest>
<application>
<activity android:windowSoftInputMode="adjustPan">
</activity>
</application>
</manifest>
It looks like AndroidManifest.xml is something that's get derived from config.xml and not something you would want to directly edit.
I would edit config.xml and sections of it are reflected into the various AndroidManifest.xml used for building Android APKs
Still facing this issue. I searched all over google could not found a solutions.
Mac OSX Sierra
Android Studio 2.3
Cordova/ Phonegap (Latest Version)
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
Gradle: installed
Error: Some of the requirements check failed
.bash_profile
================================
# Setting JAVA_HOME Path
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home"
# Setting ANDROID_HOME Path
ANDROID_HOME=“/Users/{localpath}/Library/Android/sdk”
# Setting GRADLE_HOME Path
GRADLE_HOME=“/Users/{localpath}/Library/Android/gradle/gradle-3.4”
export PATH=“${GRADLE_HOME}/bin:${PATH}”
export PATH="${ANDROID_HOME}/tools:$PATH"
export PATH="${ANDROID_HOME}/platform-tools:$PATH"
Andriod Manifest
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.company.myAPP" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="#mipmap/icon" android:label="#string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="25" />
</manifest>
Android Studio Installed SDK
Facing exactly the same error, I encountered this answer on forum.ionicframework.com:
As easy as that.
I had the problem on Mac, so I did download the SDK tools373, copy-paste it in /Users/username/Library/Android/sdk, and it worked instantly.
But I absolutly don't know what causes the issue.
And I don't know what causes the issue either, but it helped me and everything works as expected.
Facing with same error.
Maybe this info will be helpful.
In the latest Android SDK Tools (v25.3.1), the android command no longer operates as expected and instead exits with a non-zero status code and provides a message telling folks to use the sdkmanager and avdmanager commands.
try to execute android in terminal if it will return something like this:
The android command is no longer available.For manual SDK and AVD management, please use Android Studio.For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
then you need to downgrade your SDK to v25.2.5 or less. Instruction can be found here
I downgraded Android SDK
FROM
latest release 10.0(q) to API level 29
TO
9.0(pie) API level 28
by the user guide here
then added this in a .bash_profile
export ANDROID_HOME=${HOME}/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
everything works fine
I hope that it can help someone
Cordova gives me this error, when I was making my first hello world app.
I typed :
cordova build android
And I got the follwing output:
[Error: Please install Android target: "android-22".
Hint: Open the SDK manager by running: /home/nicki/Android/Sdk/tools/android
You will require:
1. "SDK Platform" for android-22
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: /home/nicki/code/cordova/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/nicki/code/cordova/hello/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
I am using Ubuntu 14.04.
Android Manifest file in my app:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
</manifest>
I also modified <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" /> to
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
and it still gave same error of android-22 (even though it was 19 in the file).
And besides that I got 23 which is even better than 22, as you can see in my screenshot below:
this can be the issue with Cordova version you are using. Each version of cordova will support only a set of android version. Please read this for more information: https://cordova.apache.org/announcements/2015/07/21/cordova-android-4.1.0.html
Just edit the files listed below as
# Project target.
target=android-23
myApp/platforms/android/project.properties
myApp/platforms/android/CordovaLib/project.properties
From the screenshot i have understand that, you have installed Android SDK Platform tool and Android SDK Build tool in version 23. So you have to change the Project target as mentioned above on those files.
It worked for me. Thanks
I'm on Windows 7 x64.
For me the problem was that default java.exe was ran from Oracle's JDK 8u40 (on PATH), while my JAVA_HOME pointed to IBM (WebSphere) JDK with WAS 8.5
After I ran
set JAVA_HOME=c:\devtools\jdk_8u40
in my shell for it to point to Oracle's JDK directory, it started finally working!
This works for me, my specific approach is: remove the reference to the oracle directory from the environment variable of path and reduce the JDK version to 1.8.0u65
I create a plugin for Cordova and I want to edit the AndroidManifest to add an attribute in the "application" tag. I know config-file to add a new tag but I don't find if I can update an existing tag.
For example, I have this AndroidManifest:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.test.testCordova" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
and I want add android:isGame=true in the <application> tag.
If i can't do this from the plugin.xml, I will create a hook to edit the AndroidManifest by myself but I hope it will not be necessary.
I ended doing a plugin hook which I didn't know existed. Plugin hooks are hooks that are defined in the plugin and that can be called before or after the plugin is added or removed (either when you run the cordova plugin cli commands or when cordova adds the plugin to the platform with cordova platform add command).
I didn't want to use hooks because I thought hooks had to be placed in config.xml and could not be linked with a plugin.
Here I added this line in the platform android section of the plugin.xml file (my requirement was a little different than the OP's but the sample may help anyway) :
<platform name="android">
<hook type="before_plugin_install" src="scripts/androidBeforeInstall.js" />
...
</platform>
And then I wrote the androidBeforeInstall.js hook script :
module.exports = function(ctx) {
var fs = ctx.requireCordovaModule('fs'),
path = ctx.requireCordovaModule('path'),
xml = ctx.requireCordovaModule('cordova-common').xmlHelpers;
var manifestPath = path.join(ctx.opts.projectRoot, 'platforms/android/AndroidManifest.xml');
var doc = xml.parseElementtreeSync(manifestPath);
if (doc.getroot().tag !== 'manifest') {
throw new Error(manifestPath + ' has incorrect root node name (expected "manifest")');
}
//adds the tools namespace to the root node
doc.getroot().attrib['xmlns:tools'] = 'http://schemas.android.com/tools';
//add tools:replace in the application node
doc.getroot().find('./application').attrib['tools:replace'] = 'android:label';
//write the manifest file
fs.writeFileSync(manifestPath, doc.write({indent: 4}), 'utf-8');
};
It's a little more complex than just adding config-file lines in plugin.xml, but once you have the good syntax it can be very powerfull.
Edit:
For some reason with only the hook in before_plugin_install, the AndroidManifest.xml was correctly updated during the platform add, but was restored at it's default state at the end of the platdorm add.
As I couldn't figure out the reason, I added the following line in the plugin.xml so the script is also launched at the end of the platform add (luckilly hooks defined in plugin.xml can be run not only when adding or removing a plugin).
<hook type="after_platform_add" src="scripts/androidBeforeInstall.js" />
For latest cordova version 8.1.2 path of AndroidManifest.xml file has been changed.
Below is how I did it and working perfectly fine.
In similar way you can also update any other configuration of AndroidManifest.xml.
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:isGame="true" />
</edit-config>
Also make sure that you added the android namespace in the root <widget> tag in config.xml (otherwise you will get unbound prefix error):
<widget ... xmlns:android="http://schemas.android.com/apk/res/android">
You are done!
If you are using cordova-custom-config you may need to add a new custom-preference to your config.xml:
<platform name="android">
<!-- ... other settings ... -->
<custom-preference name="android-manifest/application/#android:isGame" value="true" />
</platform>
My Cordova has suddenly stopped working.
It was working well when I was last working on it - around 2 months ago.
Now when I want to resume working on my project, it gives me the error:
> cordova platforms add android
npm http GET https://registry.npmjs.org/cordova-android/3.7.1
npm http 200 https://registry.npmjs.org/cordova-android/3.7.1
npm http GET https://registry.npmjs.org/cordova-android/-/cordova-android-3.7.1.tgz
npm http 200 https://registry.npmjs.org/cordova-android/-/cordova-android-3.7.1.tgz
Platform android already added.
> cordova run android
Running command: C:\Work\Eclipse\Workspace\Android\CordovaTmp\HelloWorld\platforms\android\cordova\run.bat
"C:\Work\Eclipse\Workspace\Android\CordovaTmp\HelloWorld\platforms\android\cordova\run"
ERROR: Error: Please install Android target "android-19".
Hint: Run "android" from your command-line to open the SDK manager.
ERROR running one or more of the platforms: Error: C:\Work\Eclipse\Workspace\Android\CordovaTmp\HelloWorld\platforms\android\cordova\run.bat: Command failed with exit code 2
You may not have the required environment or OS to run this project
> cordova -version
4.3.0
I have checked out these posts, but thats of no help: link 1, link 2 and link 3.
Also, I am unable to run 'android' on the cygwin shell even though I have added tools and platform-tools to my PATH variable in 'My Computer'
I am running Windows 8.1, cygwin and here is what my SDK Manager looks like:
My platforms/android/AndroidManifest.xml looks like:
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.foo.helloworld" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="#android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21" />
</manifest>
The cordova run android command needed to be run from windows powershell and not cygwin.