Cocos2dx Android: Get data from file(assets/*) failed - android

Where do you need to add your images in your Cocos2dx Android project (in Eclipse)?
They're currently in the 'Resources' folder like what is mentioned on Ray Wenderlich's blog, but I get an error when I run it in the emulator: "get data from (assets/myFileName) failed" for each image. I also added these images to the assets folder in Eclipse, and it makes no difference.
It works fine on the iOS side.
Any suggestions?

I believe you need to run ./build_native.sh in your android folder before run on Eclipse.

So the actual problem wasn't with the building or copying process.
I had a class I made that would apply the correct prefix to a CCSprite if it was an iphone, ipad, etc. And I made some changes to the CCMenuItemImage source code to incorporate this file, but the iOS and Android Cocos2dx files are separate, so the Android project wasn't using the new code, and wasn't adding the correct prefix, so it wasn't finding the image.
Thank you everyone for your answers!

You no need to add to the assets folder , when you run ./build_native.sh it will automatically add to the assets folder. Check it build successfully without any errors and then import to eclipse.

Try using
const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("testimage.png");
before giving cocos2d-x your filename.

This was the same problem I face. Actually I have solved this problem by doing:
Run the ./build_native.sh from cygwin. This step to move the asset needed to android project. Dont forget to chmod 777 -R first to your cocos project, i've got an error because the build_native.sh doesn't have permission to move the assets.
In eclipse, build it again following this tutorial. In that link, it shows how to build the cpp source + cocos2d in eclipse.
Run as android application, then the .apk will be generated.

I'm using the Cocos2d-JS version.
If you have an empty JS file that is imported in your project.json, you will get this very error on Android.
In this case, solution is to not have any empty JS files imported.

Related

Painful Unity project export to Android each build (I'm doing something wrong)

I would like to know if there is a faster way than the following steps to test Unity app with Android (gradle export):
Change something in unity
Build settings & Run --> Export (new Gradle)
Now the old gradle in the Android project is replaced, so i need to copy paste from a backup
The Res folder is also replaced, so I need to copy paste the backup one
Finally Build and Run the APK on the device
Steps 3 and 4 are obviously what makes this process painful (slow), I found the manifest.xml of the Unity android plugin, so this one stays the same (edited it directly in Unity). So am I doing something wrong ? Is there a way to update only parts of the Android project (like, if I only changed one line of a C# Script, just rebuild this one for Android)
Tell me if I'm not clear enough with my explanation :)
EDIT: I Already posted this in Unity forum but I didn't get any answer yet after a day
You can create your own Gradle file.
Put it in Plugins/Android folder and call it mainTemplate.gradle
It will use that.
As far as I know, there is no way to rebuild just part of it.
Unity does not create java files from the c# code. It creates its own modules and uses them directly.
BTW, why are you exporting at all? Why not compile directly to your device?
I just wanted an additional answer for this question even though it is a bit old (just in case anyone else in the future is wondering about this like me). I personally need to make use of both Android Studio and Unity so making a plugin wasn't really an option for me.
Now I have a custom gradle file as explained in the accepted answer. However I have also added an additional resource folder (Explained well by Android here: https://developer.android.com/studio/write/add-resources.html).
You basically just have to edit your custom gradle file to add paths to both resource directories. Add the resources you don't want Unity to overwrite to the other resource folder.
Now every time you rebuild to the project the resources remain and you don't have to copy them back in.
You can export a formal Android project first, using this project to build your final apk.
Then You could write an EditorUtil script in you Unity project, The script does following things:
1.export an temporary Android project to another folder.
2.copy assets folder and jnilib folder or any other folders you want to replace in your formal Android project.
Everytime you want export your project, just trigger the export function in you Unity Editor, It will copy and paste folders automaticlly, then your formal project will be ready for building.

How to create apk on mac using xbuild\msbuild with multiple project files

I have being trying to create an APK file for my Android App. The Project itself contains multiple .csproj files so I need to include them as well as packages and other necessary information. Can you either do this by selecting the .sln file which works to create my IPA file using mdtool. But for me will just run successfully(doesn't have any error) but will not create the APK file. So I thought I would have to use either /t:PackageForAndroid or /t:SignAndroidPackage. But I get the error message PackageForAndroid not found in project. I was unsure what to do here if the problem is that I have to target a file or node in my project that is matched to that target(if this is correct where could I find this?) If I just have to use either of these as target how should it work correctly as I also tried it with MSbuild and this did not work either.
I have tried to use Debug and Release as the /p:Configuration both have the same result. Ad Hoc doesn't work. Then I tried to use a .csproj file as I seen most examples contain that, but this is not working right for me because I have multiple .csproj files as well as a lot of other information needed to build the app. I have tried to use the Include, command unsuccessfully, trying to target all .csproj files as well as just targeting the main build but this has not worked.
How can I create this APK file correctly? I think I am close as if I am not getting any error messages, I am just not creating it correctly. I have on the terminal on the mac and using Bamboo(as this is where I get the project from)and the results are the exact same. Also note that this project successfully builds on the emulator and on an android phone so there are no problems with the project itself.
I fixed the messages by re-installing the msbuild from a github repo, then I used which msbuild to find my location of msbuild. Then I added it as an executable in Bamboo. Then I added a command task in my bamboo plan which then add the MSBuild as its executable and the argument was this:
CustomerApp.Droid/CustomerApp.Droid.csproj /t:SignAndroidPackage /p:Configuration=Release

Where is build.xml in android

I m making an app which shares its file from assets folder and I m sharing an xml file to other app it gives me this exception
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
I got this TUTORIAL but at point number 7 it says that "ADD THIS SECTION TO THE END OF build.xml" so where can I get this build.xml??
And any way around to resolve this exception??
I m using MAC OS X
Run android update project -p ..., where the ... is the path to the project. This will create or update the build.xml and related command-line build files. This assumes that your SDK's tools/ directory in your PATH; otherwise, you will need to fully-qualify the path to the android command.I hope it will helps you .
Follow this Procedure To Use build.xml
Go to your Android SDK installation, and open the file "tools/ant/build.xml", copy the complete "test" target and paste it in the "build.xml" of the test project, before the import of build.xml, so before the comment starting with "Import the actual build file". There is more information on how to customize targets in that comment.
If its Confusing Follow this for Complete Ant....
Hope You understand..

Changes to myApp.js files are reverted back to normal when the project is build - Cocos2dx

I am trying to do some changes to my myApp.js file of coco2dx project for android in eclipse but I am not able to do it.
I am actually trying to change the default background image of my app. But when I run my project all the changes goes back to before values
For Eg: This is the default line wer we are setting our background image
this.sprite = cc.Sprite.create("res/HelloWorld.png");
I am changing it to the following line:
this.sprite = cc.Sprite.create("res/CloseNormal.png");
But when I run my project CloseNormal.png goes back to HelloWorld.png
I am using:
OS: Win7
Cocos2d Ver: cocos2dx 2.2.2
Why is this happening. Can anybody help me?
Maybe the Resource folder permissions are not correct so using cygwin go to the Resources folder present in ur project.android folder of ur project and execute the following command:
chmod -R 777 *
Also refer to this link
Hope it helps :)

Titanium Appcelerator Android module : How to create a proxy?

This is not a question but is an answer to the issues I was stuck up while creating custom Android module for Titanium appcelerator.
I was able to run the ExampleProxy provided by the framework but was having problems creating my own Proxy class.
I was able to access the proxy. After lot of search I got the reference of following question -
http://developer.appcelerator.com/question/153993/how-to-create-a-proxy#answer-264746
Following response partially works-
"Thank you very much Benjamin Bahrenburg for the clarification. Also i
thank Mads for your quick response.
Exact answer i was looking for : Need to remove the files in the bin,
libs, and build folder. Then do a clean, in Eclipse. After all of that
it tends to build. Please make sure you are using Ti 3.1.0 ( not 3.1.1
which has an issue)."
In addition on windows 7 machine I had following observations-
The Module-generated folder in C:\Users\username\AppData\Local\Temp\ must be deleted.
In the module folder delete following contents - entire contents of bin and libs and delete everything in build except \build\generated\Application.mk
It cost my 1 day to solve this problem.
to successfully create and run a ViewProxy, you have to:
change its file/class name (from ExampleProxy) to ViewProxy
clean the dirty files, including: build/, dist/, and some "lib.so " files in libs/ folder.
execute ti clean in your "Titanium app" folder.
your ViewProxy is not the same as the module name. e.g. your module name is: "GaodeMapModule", your proxy name should not be: "GaodeMapProxy", it doesn't work.

Categories

Resources