Android Project Template

Hi guys,

I’ve been trying to figure out a clean way to setup Android project. I don’t really want to modify sample and continue the development inside Urho folders. An out of Urho/using Urho as a library (AAR for Android) approach is preferred. Currently, on Windows, I have a very clean CMake based project structure working, however, I wonder if there is any Android example that I could follow.

Edit: BTW, I have studied some CMake, Gradle, NDK, etc. No progress yet.

Cheers

1 Like

This is my HelloWorld project that I used to figure out how to work on Android
image

HelloWorld and Urho3D
image

Here is my CMakeLists.txt -

# Set CMake minimum version and CMake policy required by UrhoCommon module
cmake_minimum_required (VERSION 3.10.2)
if (COMMAND cmake_policy)
    # Libraries linked via full path no longer produce linker search paths
    cmake_policy (SET CMP0003 NEW)
    # INTERFACE_LINK_LIBRARIES defines the link interface
    cmake_policy (SET CMP0022 NEW)
    # Disallow use of the LOCATION target property - so we set to OLD as we still need it
    cmake_policy (SET CMP0026 OLD)
    # MACOSX_RPATH is enabled by default
    cmake_policy (SET CMP0042 NEW)
    # Honor the visibility properties for SHARED target types only
    cmake_policy (SET CMP0063 OLD)
endif ()

# Set project name
project (HelloWorld)
# Set CMake modules search path
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../Urho3D/CMake/Modules)
# Include UrhoCommon.cmake module after setting project name
include (UrhoCommon)
# Define target name
set (TARGET_NAME HelloWorld)

define_source_files (
    GLOB_CPP_PATTERNS 
    ${CMAKE_SOURCE_DIR}/Source/* 

    GLOB_H_PATTERNS 
    ${CMAKE_SOURCE_DIR}/Source/*
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})

define_resource_dirs ()

setup_main_executable ()

I tried hard, but no result on Android at all.

What the errors are?

I also had this dilemma in our Android project. There is one sample project template here https://github.com/Lumak/Urho3D-Android-Project
If I remember correctly we had issues between Kotlin, Gradle, and Android studio they didn’t seem to like each other version numbers or something. Probably the real reason why I did not succeed was that I am a complete noob. :sweat_smile:
What we ended up doing is that we worked normally in project scaffolding way and when it was time to build to android we edited our main.cpp so that it would be similar to samples.

I hope this helps you forward in your quest. If you figure this thing out plz let me know. :blush:

EDIT:
Maybe you can find answer here

Thank you GastaGaming! I think they are not using AAR or “out of Urho folder”. But I’m studying them hard.

@johnnycable there are too many issues, I cannot say which piece I missed, when I’m still trying to put the puzzle together.

The whole building system of Urho3D is complicated, people need to know the implementation details to work on different platforms. I don’t know it is common or we just need more documents on these topics. It seems that we need some start point / template/ sample / wizard, to make our code run first.

Since I’m not alone, so I hope I can make it work and post my steps / example here.

1 Like

Before the AAR there is no easy way to use Urho3D as library in Android build. And, even the Rake scaffolding task that we provide does not support Android build. With AAR I see there is a chance to pull this off. YMMV.

1 Like

I wonder if these AARs can work since they are too small (after excluding the “assets”), the main parts are in the *.so files. In other words, dynamic libraries are used.

I have tried setting URHO3D_LIB_TYPE to STATIC (-DURHO3D_LIB_TYPE=STATIC, according to document, it’s actually the default) and passing it to gradle, but it does not work.

image

1 Like

The whole Gradle + CMake + Android Studio for NDK thing is horrible. Weekend ends now, still no progress.

We publish AAR at bintray here like ay other maven artifacts out there.

This week I hope I can crank a windows pc open, so I can test this thing. Today just it took 3 hours to create a bootable usb… :grimacing: :grimacing: :grimacing:

IMHO, It’s not a Windows specific issue.

Uploaded the testing project -

Hi weitjong,

I found that in the AAR I build, there is no “tree” folder, and from bintray you linked, there is this folder in the archive. I find it is the reason why the AARs I built were very small.
Do you know the cause of the problem?

image

Thanks,
Kai

You didn’t provide any information on the errors/warnings, if any, on the build process. As such, my guess on what has happened is as good as yours and anyone else. All the steps taken by CI to build and publish the AAR to Bintray is reproducible. If you cannot get same result with the same steps then It may be host machine or build environment issue. The steps are not verified yet on Windows host so far, AFAIK. Ideally it should just work since it is Java based.