1

I'm trying to build my cocos project to android.

At first, I ran the following command:

cocos run -s {my_project_path} -p android

And I got errors of packages and symbols that weren't found, here is the first error:

error: package org.apache.http does not exist
import org.apache.http.Header; 

and after the list of items that weren't found:

BUILD FAILED
......\AppData\Local\Android\sdk\tools\ant\build.xml:597: The following error occurred while executing this line:
......\AppData\Local\Android\sdk\tools\ant\build.xml:716: The following error occurred while executing this line:
......\AppData\Local\Android\sdk\tools\ant\build.xml:730: Compile failed; see the compiler error output for details.

I've read that it can be because my android project version was 23.

So I edited the version field in the android.properties file to 22

and ran the next command:

cocos run -s {my_project_path} -p android --ap android-22.

The first build output lines are saying it uses the android 22 api, but in the middle of the build, for some reason it starts to use version 23 and I receive the same errors above.

Did anybody have those errors?

Thank you, Ben

Ben
  • 31
  • 2

3 Answers3

0

That's because HttpClient isn't supported in android 6.0:

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html

You can read details here:

https://stackoverflow.com/a/32153434/1264375

Anyway easiest way to fix this is to change api level to 22 (as you said). But you have to do it in AndroidManifest (in my case I'm using api level 19):

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

Also you have to change api level in eclipse project settings in Android section.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Makalele
  • 7,431
  • 5
  • 54
  • 81
0

If you want to use Android API 22, make sure you downloaded it via the SDK Manager.

One of the solutions to make it work with Android API 23 is by copying the file

[ANDROID SDK PATH]\sdk\platforms\android-23\optional\org.apache.http.legacy.jar

to

[PROJECT PATH]\cocos2d\cocos\platform\android\java\libs

before compiling your project. It worked for me.

Source: http://discuss.cocos2d-x.org/t/android-23-6-0-compile-errors-import-org-apache-http-header/26876/2?u=theslyest

theSlyest
  • 429
  • 1
  • 6
  • 16
0

Like the other comment said HttpClient isn't supported in android 6.0:

So, follow steps here. Worked for me and some others. http://discuss.cocos2d-x.org/t/cant-compile-to-android/26874/3

master_dodo
  • 1,203
  • 3
  • 20
  • 31