phonegap 3.0 wants android 17, but I want android 18

烈酒焚心 提交于 2019-12-18 10:59:07

问题


While experienced with phonegap and xcode, I'm new to android. I have installed phonegap 3.0 ...

npm install phonegap
phonegap --version
3.0.0-0.14.3

I've installed adt-bundle-mac-x86_64-20130729. The command line tools (eg: android) seem to work fine. When I try to add android as a platform ..

phonegap local build android

I get ...

[error] Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.

I see similar questions still unanswered ... Phonegap 3.0 CLI issue android target number in build app

When I do install android-17 it works fine, which is cool, but I need to use android-18 so I can use BLE.

I see that Fil Maj apparently fixed this issue on Jul 31 ... https://git-wip-us.apache.org/repos/asf?p=cordova-android.git;a=commitdiff;h=c2c5f710

.. but I don't appear to have that fix in the version of phonegap I downloaded. I thought perhaps it was only in cordova, so I installed that too, but ran into the same issue.

I tried hacking the four js files in the npm directories that contain the check directly, but that didn't take (ie: the error persisted).

Can anyone please suggest either ...

1) how to download a version of phonegap/cordova with the problem fixed, or

2) how to tell phonegap/cordova which version of android I'd like to target

Thanks so much ...


回答1:


Find file android_parser.js in Windows it is undr path:

C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\cordova\src\metadata

change in file android_parse.js

OR if You are makking application from PhoneGap not Cordova:

C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\phonegap\node_modules\cordova\src\metadata\android_parser.js

go to line: 57

if (output.indexOf('android-17') == -1) {

and change it for:

if (output.indexOf('android') == -1) {

This will let You not to wory about future :)

But then You can occur this Error

[Error: An error occured during creation of android sub-project.
]

To fix it You will have to goto this path:

C:\Users\USER_NAME\.cordova\lib\android\cordova\3.1.0\framework\project.properties

And change this line:

target=android-17

To this:

target=android-19

Or whatever is Your Android SDK version

What to do if You want to use Android 2.2 ?

Just simple go to:

Your_Project_Folder/platforms/android/AndroidManifest.xml

And change:

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

To:

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />

And after that import Your project to Your IDE

Enjoy :)




回答2:


If anyone gets here using cordova and/or chrome mobile app toolchain. I edited platforms/android/project.properties directly to target=android-19 and it built.

cheers




回答3:


Simply open your AndroidManifest.xml file and set minimun and targeted version. In your case 18. Same answer to question Phonegap 3.0 CLI issue android target number in build app.

AndroidManifest.xml file is located in: YOURPROJECT\platforms\android. If you need more assistance ask, will try to help you. Post your AndroidManifest.xml file so I can check.


回答4:


Go to \cordova\src\metadata\android_parser.js in function check_requirements and change the lines 56,57,66 from 17 to 18. It will then be ok.




回答5:


Make sure you have the latest version:

  • PhoneGap: sudo npm update -g phonegap
  • Android SDK: depending on how you installed it, if you did it through brew: brew update android-sdk

Then run aandroid, and download the latest API.

Then PhoneGap will use the latest API by default when running phonegap build android.

If you need to update a current project, run inside the project folder:

phonegap platform update android

And now if you run build again, it should use the latest version.




回答6:


I had installed cordova through npm, therefore to make it work I modified target in ~/.cordova/lib/npm_cache/cordova-android/3.6.3/package/framework/project.properties




回答7:


I think you have the wrong version of Phonegap, mine says 0.3.0-0.15.0. I think Fil's fix would definitely have made it into the final build, so I think you must be doing something goofy when installing Phonegap. This is what I did:

npm install cordova -g (or I guess in your case it would be Phonegap and not cordova.) This will install cordova (or phonegap) globally so that you can access it anywhere with the 'cordova' command. If you already have it installed try npm update instead of npm install.

Navigate to a workspace location, like C:\workspace.

Type cordova create MyApp which will create a Cordova project at C:\workspace\MyApp. The workspace will have the following folders:

/www/ - where you place all of your HTML and JavaScript

/platforms/ - this will have folders for android, ios, and any other platforms you add. Your stuff from /www/ will get copied over here in the right place for each platform. This is where you would edit platform-specific files, for example, to change the target-sdk, you want to edit /platforms/android/AndroidManifest.xml.

/plugins/ - this is where all of the plugin code will go when you do cordova plugin add {link}. I can't think of any reason why you should ever edit anything in this folder (but there probably are some good ones.)

/merges/ - any files here will get merged with the corresponding files in /www/ and pushed into /platforms/, see the documentation.

After running the create command, you need to add the platforms:

cd MyApp

cordova platform add android -d - the -d gives us debug info

cordova build android - this will build the android app and you will see stuff from /www/ copied over to /platforms/android/assets/www.

One If you are still having issues, did you try what it says in the output, that is, running android from the command line? This will bring up the "Android SDK Manager", make sure that you have the latest version of the SDK installed as well as the latest Android SDK Tools and Android SDK Platform-tools (mine are 22.0.5 and 18.0.1, respectively.)

There may also be issues if you have never created an Android emulator object (use the AVD manager) although that sounds less likely.




回答8:


C:\Users\USER_NAME.cordova\lib\android\cordova\3.1.0\framework\

should be in bumerang's anser

C:\Users\USER_NAME.cordova\lib\android\cordova\3.1.0\framework\project.properties




回答9:


PhoneGap Build now supports an option to set the Android SDK version. It is documented here but basically what you need in config.xml is:

  <preference name="android-targetSdkVersion" value="18" />

It will then set the property correctly in AndroidManifest.xml.

Note: This supposedly only works for PhoneGap build, but I am using the Ionic command line tools (on Cordova 5.1.1) and it appears to work fine for me too.




回答10:


reading from the release notes of version 3.1.0, it says:

  • Incremeting version check for Android 4.3 API Level 18
  • Upgrading project to Android 4.3

Therefore, upgrading to Phonegap 3.1.0 should do the trick.




回答11:


You are in the wrong place guys

YOU SHOULD TRY THIS: phonegap local build android

this will add the android to your platforms folder...



来源:https://stackoverflow.com/questions/18789524/phonegap-3-0-wants-android-17-but-i-want-android-18

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!