cordova phonegap - How to use android API level 21

2019-08-14 20:34发布

问题:

Hey I forked the push notification plugin (https://github.com/alexislg2/PushPlugin) and added it to my project.

The project won't compile with cordova build because I have a error: cannot find symbol error.

The reason is that I use in the plugin Notification.setCategory() method which is Android SDK 21.

How to force cordova to compile using API level 21?

I installed the android 21 sdk build tools + I set <preference name="android-targetSdkVersion" value="21" /> in my config.xml

But cordova keeps trying to compile with android 19. What is wrong?

Thanks

回答1:

This is the progress of Cordova updating to android-21, android platform plugin v4.0 will support lollipop: https://issues.apache.org/jira/browse/CB-8026

There is an issue about cookie and a temporary workaround: http://tol8.blogspot.ca/2014/11/fixed-apps-cordovaphonegap-targeting.html

I would suggest waiting for the next version, looks like 3.7.1 also updated the target api level.

I am not using cookie related feature in my project, so I just replaced "android-19" with "android-21" in

platforms/android/CordovaLib/project.properties

And adds preference in config.xml

<platform name="android">
    <preference name="android-targetSdkVersion" value="21" />
</platform>

Another workaround (but ugly) is change the system cache of android plugin code:

~/.cordova/lib/npm_cache/cordova-android/3.6.4/package/framework/project.properties

---- Update ----

A better way of updating platform plugin will added in Cordova 4.2.1 (currently 4.1.2): https://issues.apache.org/jira/browse/CB-8239

$ cordova platform add <URL>