Can't compile Cocos2d-x project - java

I've just installed Cocos2d-X and whenever i try to compile newly created project i got the following error.
I tried to uninstall and install java again and nothing changed.
I'm using the following command to compile.
> cocos.py compile -p android --android-studio
And i got the following Error :
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':libcocos2dx'.
> Failed to notify project evaluation listener.
> javax/xml/bind/annotation/XmlSchema
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option
to get more log output.
BUILD FAILED
and sometimes i get this error
> Could not initialize class com.android.sdklib.repository.AndroidSdkHandler
instead of
> javax/xml/bind/annotation/XmlSchema

I had a similar problem. For me uninstalling java 9 and installing java 8 did the trick.
If you are in Android studio you could go to File -> Project Structure and change the JDK Location to wherever you have java 8 installed

From what I understand command line compile doesn't work for android-studio anymore.
Best way is to try install latest android-studio and latest cocos2d-x. Then build apk and test on device...
First time you run android-studio it will download few things. And first compile for a projct will take ages.. but after that everything will be pretty fast

Related

I can not run anything with gradle [duplicate]

This question already has answers here:
Unable to locate tools.jar
(35 answers)
Closed 2 years ago.
So, I have this problem, and it is that every time I try to run Gradle from Eclipse it gives me this error:
Working Directory: C:\Users\Owen\eclipse-workspace\SimpleMultiplycationProgram\SimpleMultiplycationProgramApp
Gradle user home: C:\Users\Owen\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3.1
Java Home: C:\Program Files\Java\jre1.8.0_251
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run
:SimpleMultiplycationProgramApp:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':SimpleMultiplycationProgramApp:compileJava'.
> Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_251 contains a valid JDK installation.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 13s
1 actionable task: 1 executed
So, I started trying to fix this but all the stackoverflow questions and tutorials say to do something like running ./gradle biuld it gives me this error (from cmd):
'.' is not recognized as an internal or external command,
operable program or batch file.
`/gradle biuld' gives me:
'/gradle' is not recognized as an internal or external command,
operable program or batch file.
and gradle biuld gives me:
'gradle' is not recognized as an internal or external command,
operable program or batch file.
and C:\Users\Owen.gradle is a folder, so what is going on?
This seems to be about two unrelated problems. For one, you don't seem to have gradle on your PATH, hence why the command is not recognized. And then you're also missing rt.tools. See if this other question helps you solve it. You seem to have downloaded only the JRE and not the JDK.
It appears to me that you are using a JRE instead of JDK. Possible that you pointed $JAVA_HOME environment variable to a JRE when it was meant to be JDK.
To use gradle, if you have a wrapper in your project directory named "gradlew", call it like this: ./gradlew ...
But if you don't have it, you should run the "wrapper" task to generate them.
You can also install gradle instead. But keep in mind it doesn't help with your issue. Take a look at this article for installing gradle.

Cordova Emulating/Building Android always returning Gradle Error

I am currently trying to run an emulator on Android on my Mac PC through Cordova. But it seems like I always get issue and it always comes down to Java Environment possibly not being correct. When I try to do either a build or a emulate, I get the following error:
Error: /cordova_app_directory/platforms/android/gradlew: Command failed with exit code 1 Error
output:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '9.0.1'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
I have gone through multiple ways of trying to fix this. This includes updating java development enviroment (which its 10.0.1) and also update Gradle (which is 4.4). I also tried removing and re-adding the platform back in but it doesn't work.
Does anyone have any idea of what could be causing this issue?

react native java.lang.ExceptionInInitializerError

I'm trying to make React Native work on an emulator. I'm using Genymotion it works fine, the virtual machines opens without any problem and i have added the SDK to its configuration.
I have the emulator opened and working but when i run react-native run-android i get the following error.
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
java.lang.ExceptionInInitializerError (no error message)
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
I've found out that a possible problem is that i was runnig java 9 and React Native requires java 8 instead (https://github.com/facebook/react-native/issues/11755)
So i did the following
I tried changing the version by doing this
sudo update-java-alternatives --set java-8-oracle
then checking the version with
javac -version
it returns javac 1.8.0_131
If i run the app again i still get the error from above
But when i echo $PATH i see that it is still referencing the java 9 folder
echo $PATH /home/andrei/.nvm/versions/node/v7.5.0/bin:/home/andrei/bin:/home/andrei/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/home/andrei/Android/Sdk
How do I change that or fix this problem?
To fix this problem
But when i echo $PATH i see that it is still referencing the java 9 folder
echo $PATH /home/andrei/.nvm/versions/node/v7.5.0/bin:/home/andrei/bin:/home/andrei/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/home/andrei/Android/Sdk
in The Home directory open .profile
add the following
PATH="$PATH:~/usr/lib/jvm/java-8-openjdk-amd64/bin"
in this case i'm adding the path to java 8 folder because that is the one i need to use The React-Native according it its specification
https://facebook.github.io/react-native/docs/getting-started.html
after setting the PATH you need to make it available inside the terminal you are executing the react-native app by using the following script
source .~/.profile
this should get you passed the initial problem with the java 9

Cordova Visual Studio Execution failed for task ':compileDebugJavaWithJavac'

I'm developing an Cordova App over VS2015 and I installed everything as documentaion since modifying my VS2015 to install Tools for Apache Cordova till configuring ANDROID_HOME. Everythings was going fine untill I added a new plugin. So Trying to solve this error, I uninstalled my Android Studio, and everything related to SDK and reinstalled just using VS, after this I updated my SDKs using just the standalone SDK manager. Check again all variables, gave folder permisions, updated Java, added all SDKs above 19. But nothing is working on. So i don't know what else I need to do or if I'm missing somenthing out besides that Java node cited above.
cordova-plugin-firebase
Well, Im going to show my config below. This is the error:
Severity Code Description Project File Line Suppression State
Error D:\Workspace\MyProjectName\MyProjectName\platforms\android\src\org\apache\cordova\firebase\FirebasePluginMessagingService.java:102: error: cannot find symbol MyProjectName 1
Error if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.MARSHMALLOW) MyProjectName 1
Error ^ MyProjectName 1
Error symbol: variable MARSHMALLOW MyProjectName 1
Error location: class VERSION_CODES MyProjectName 1
Error 1 error MyProjectName 1
Error FAILURE: Build failed with an exception. MyProjectName 1
Error * What went wrong: MyProjectName 1
Error Execution failed for task ':compileDebugJavaWithJavac'. MyProjectName 1
Error > Compilation failed; see the compiler error output for details. MyProjectName 1
Error * Try: MyProjectName 1
Error Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. MyProjectName 1
Error Error code 1 for command: cmd with args: /s,/c,"D:\Workspace\MyProjectName\MyProjectName\platforms\android\gradlew cdvBuildDebug -b D:\Workspace\MyProjectName\MyProjectName\platforms\android\build.gradle -Dorg.gradle.daemon=true -Pandroid.useDeprecatedNdk=true" MyProjectName 1
This is all variables realated:
ANDROID_HOME = C:\Program Files (x86)\Android\android-sdk
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_121
Path = %ANDROID_HOME%\tools; %ANDROID_HOME%\platform-tools
As you can see below. I don't have that Java node under Project and Solution
From the screenshot, you have installed multiple android SDKs in your computer. The SDK manager you opened is under path:C:PROGRA~2\Android\ANDROI~1.
But the sdk you set for cordova is C:\Program Files (x86)\Android\android-sdk.
Please check the SDK under C:\Program Files (x86)\Android\android-sdk.
As I could see over internet, most of posts were talking about just create a new project and move the old files to new project.
Well, my project is too big and I refused to do it. So I spent a few more hours trying to figure out how to solve it.
Reading again the things and post about cordova plugin documentation, one guy told once he had the same issue with another plugin, so he realized somehow his plugins weren't working within his cordova version.
So using Node.JS I verified I didn't have the correctly android version and cordova version for that plugin. I don't know why compiler was not rewriting plaftorm correctly. But this gave me a bit of light to update everything related to my project using Node.JS, outside VS2015.
My steps were exactly this:
1 - Download and installed Node.JS https://nodejs.org/en/download/
2 - Downloaded and installed Git For Windows http://gitb.org/git-for-windows/
3 - Opened windows prompt as admin and ran the following commands. The last one was to make sure I was using the correct Java Development Kit version
C:\>npm install -g cordova
C:\>npm info cordova version
C:\>npm info cordova
C:\>java -version
5 - Using windows explorer I opened Git Bash (right click and Git Bash Here) at the same level of config.xml. Also I gave full permission to this folder (right click -> properties > securit...)
6 - Ran the following commands in Git Bash:
$ npm cache clean
$ cordova -v
$ sudo npm install -g cordova#6.3.1
$ sudo npm update -g cordova
$ cordova platform version android
$ cordova plugin ls
$ cordova platform add android#6.1.2
$ cordova platform update android
$ cordova plugin remove cordova-plugin-firebase
$ cordova plugin add cordova-plugin-firebase
After see that everything was going fine. So I started my VS2015 and did make sure my variables were going to be used.
7 - Tools -> Options . Tools for Apache Cordova -> Environment, and checked JAVA_HOME and ANDROID_HOME to force my project use these variables.
And finally I could see my project compile with no errors.
Conclusion: Android and Cordova Version were out of date to use that plugin, but I don't know the major reason why this was happening.

Can't Build Cordova Android App - Java Error Appears

I'm using ionic and I run ionic build android. The following error appears.
:CordovaLib:compileDebugJava/Users/jasontanner/Documents/ion/fip/platforms/android/CordovaLib/src/org/apache/cordova/CordovaResourceApi.java:31: error: package org.apache.http.util does not exist
import org.apache.http.util.EncodingUtils;
^
/Users/jasontanner/Documents/ion/fip/platforms/android/CordovaLib/src/org/apache/cordova/CordovaResourceApi.java:430: error: cannot find symbol
byte[] data = base64 ? Base64.decode(dataPartAsString, Base64.DEFAULT) : EncodingUtils.getBytes(dataPartAsString, "UTF-8");
^
symbol: variable EncodingUtils
location: class CordovaResourceApi
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':CordovaLib:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.663 secs
/Users/jasontanner/documents/ion/fip/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /Users/jasontanner/documents/ion/fip/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/jasontanner/documents/ion/fip/platforms/android/build.gradle,-Dorg.gradle.daemon=true
I've adjusted the appropriate files to run on Android 22 SDK. Outside of that, I've made no other changes to the android code. Any help on how to fix this would be awesome. Thanks!
Try making sure you have updated all of your libraries (ionic, cordova and so on) by running npm update. If this doesn't work I would check you have the latest JDK installed.
Finally try removing then re-adding the android platform from your project with the following commands
ionic platform remove android
ionic platform add android
If your using a mac, you could also try running the build command as sudo eg sudo ionic build android. I have come accross this when the libraries (such as ionic and cordova) have been installed with sudo. You can see more at npm throws error without sudo. Look into the NVM option which is the best way to move forward.
Could not find any version that matches com.android.support:support-v4:24.1.1+.
Solved it through reinstall of the whole Android support repository in Android SDK. It may crash.

Categories