Jump to content

[solved] How to compile C++ Project for Android


beo6
 Share

Recommended Posts

Hello Everyone,

 

i created a C++ Project and compiling etc. works nice on Windows.

 

Now i wanted to test it on Android so i published the project for Android but it gave me Errors.

 

then i linked the new .cpp and .h files into the Source-Folder just like the App.cpp and App.h files that are already linked there.

 

But i still get this Error:

C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/App.o: In function `StoreWorldObjects(Leadwerks::Entity*, Leadwerks::Object*)':
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/App.cpp:33: undefined reference to `Player::Player(Leadwerks::Entity*)'

 

Not sure what i am doing wrong.

Will try to compile a completely new Project for Android now.

 

 

//Edit:

Compiling a clean Android project works.

 

I have now found the Application.mk file where i need to add the source files at "LOCAL_SRC_FILES"

 

Now i get different errors:

C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp: In constructor 'NextMap::NextMap(Leadwerks::Entity*)':
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp:15: error: invalid conversion from 'void (*)(Leadwerks::Entity*, Leadwerks::Entity*, float*, float*, float)' to 'void*'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp:15: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)'
make: *** [C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/NextMap.o] Error 1
make: *** Waiting for unfinished jobs....
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp: In constructor 'Player::Player(Leadwerks::Entity*)':
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:10: error: invalid conversion from 'void (*)(Leadwerks::Entity*)' to 'void*'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:10: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:11: error: invalid conversion from 'void (*)(Leadwerks::Entity*, Leadwerks::Entity*, float*, float*, float)' to 'void*'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:11: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:12: error: invalid conversion from 'void (*)(Leadwerks::Entity*)' to 'void*'
C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:12: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)'
make: *** [C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/Player.o] Error 1

 

I suppose that this are some issues that the code needs to be a bit different for Android.

 

Edit:

I only used parts of this tutorial. Http://www.leadwerks.com/werkspace/page/tutorials/_/class-hooks-r38

 

So it seems they are not android compatible?

Link to comment
Share on other sites

I got it to compile now.

 

I typecasted the methods to (void*) in AddHook

   entity->AddHook(Entity::UpdateWorldHook,(void*)UpdateWorldHook);
   entity->AddHook(Entity::CollisionHook,(void*)CollisionHook);
   entity->AddHook(Entity::DrawHook,(void*)DrawHook);

 

i don't like this way because i am pretty sure it is dirty and is causing the crash when i try to run it.

 

06-04 02:44:56.058: A/libc(8712): Fatal signal 11 (SIGSEGV) at 0x00000018 (code=1), thread 8738 (Thread-567)

 

But i have still no idea how to solve it. Because everything is working nicely on Windows and i have mostly just followed the tutorial from Josh http://www.leadwerks.com/werkspace/page/tutorials/_/class-hooks-r38

Link to comment
Share on other sites

I haven't changed the gameobject class and when I keep it just like in the tutorial it is working on windows when I compile with visual studio.

 

but the exact same code won't compile with eclipse for android.

 

//edit: just noticed. I have posted this in programming but I should have posted this in the android forum i think.

Link to comment
Share on other sites

If you need the project i could send it to you. It might just take its time to upload. Or maybe only the source.

 

 

To give some more information to possibly help to find the issue:

 

The GameObject in my project is exactly as in the tutorial.

 

The Player Object however i only added an entity parameter to the constructor.

Player::Player(Entity* setEntity)
{
 entity = setEntity;
 entity->SetUserData(this);
 //Enable the hooks this class uses
 entity->AddHook(Entity::UpdateWorldHook,UpdateWorldHook);
 entity->AddHook(Entity::CollisionHook,CollisionHook);
 entity->AddHook(Entity::DrawHook,DrawHook);
}

 

since i have seen other people here doing it this way and that it is working on windows i think that is ok.

 

 

Thanks anyway for looking at it.

Link to comment
Share on other sites

Source:

http://code-i.de/LE3/Source.zip

 

as i have written in the chat:

It does not compile on Android when i stick with the tutorial.

 

It only compiled when i typecasted the hook-method to (void*)

but it crashed on my android device as soon as i started the game.

 

 

On Windows it always compiles and runs without any crash.

 

 

And i have seen in the main.cpp in the c++ project template that you typecast a hook method yourself to (void*) on line 25:

Leadwerks::System::AddHook(System::DebugErrorHook,(void*)DebugErrorHook);

Link to comment
Share on other sites

Hi Josh,

 

first i need to thank you so much.

I tried your Project and it compiled and was running perfectly on my android device.

 

I checked the code and noticed that you also typecasted the hook methods to (void*) so at least i was not completely wrong with my idea.

 

Then i started to remove line by line of my code on loading a map to see what is causing the Crash "Fatal signal 11 (SIGSEGV)".

 

I came to this part where i check the filesize of the map-file:

if ( FileSystem::GetFileSize(mapfile) > 0 ) {
  //map loading stuff
}

 

As soon as i removed that line and loaded the map without checking filesize it didn't crashed.

 

So it seems the method "FileSystem::GetFileSize()" causes a Segmentation fault on Android.

 

 

 

Thanks for being so patiently when i looked for the error in the wrong place. :)

Link to comment
Share on other sites

  • 3 weeks later...

Create a default CPP project.

 

Replace App.cpp with this:

#include "App.h"

using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}

App::~App() { delete world; delete window; }

Vec3 camerarotation;
#if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS)
bool freelookmode=true;
#else
bool freelookmode=false;
#endif

bool App::Start()
{
   System::Print(FileSystem::GetFileSize("Maps/start.map"));

   //Create a window
   window = Window::Create("CPPTEST");

   //Create a context
   context = Context::Create(window);

   //Create a world
   world = World::Create();

   //Create a camera
   camera = Camera::Create();
   camera->Move(0,2,-5);

   //Hide the mouse cursor
   window->HideMouse();

   std::string mapname = System::GetProperty("map","Maps/start.map");
   Map::Load(mapname);

   //Move the mouse to the center of the screen
   window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);

   return true;
}

bool App::Loop()
{
   //Close the window to end the program
   if (window->Closed()) return false;

   //Press escape to end freelook mode
   if (window->KeyHit(Key::Escape))
   {
       if (!freelookmode) return false;
       freelookmode=false;
       window->ShowMouse();
   }

   if (freelookmode)
   {
       //Keyboard movement
       float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Time::GetSpeed() * 0.05;
       float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Time::GetSpeed() * 0.05;
       camera->Move(strafe,0,move);

       //Get the mouse movement
       float sx = context->GetWidth()/2;
       float sy = context->GetHeight()/2;
       Vec3 mouseposition = window->GetMousePosition();
       float dx = mouseposition.x - sx;
       float dy = mouseposition.y - sy;

       //Adjust and set the camera rotation
       camerarotation.x += dy / 10.0;
       camerarotation.y += dx / 10.0;
       camera->SetRotation(camerarotation);

       //Move the mouse to the center of the screen
       window->SetMousePosition(sx,sy);
   }

   Time::Update();
   world->Update();
   world->Render();
   context->Sync(false);

   return true;
}

 

Publish the project for Android.

 

Runs fine. Prints 0 for the size, because we had to do some funny things for the Android file system.

 

 

Link to comment
Share on other sites

That's a different issue.

 

I had to implement a "virtual" file system because Android:

-Doesn't allow apps to have folders with files in them.

-Doesn't allow two files to have the same names, even if the extensions are different.

 

The command std::string FileSystem::GetAppDataPath() returns the correct file path for IO operations. Presently only Windows and Mac are supported.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...