-1

I am trying to run my sdl game on Android, I followed lazyfoo's tutorial to run the helloworld , which worked fine, later I imported my project, this project source works fine in windows without any error, but I am now seeing many errors in my files, I am new to android , I feel I have messed up with path's to my source files. below is the error:

error

Android.mk(inside src dir):

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := main

SDL_PATH := ../SDL2

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include $(LOCAL_PATH)/../SDL2_image/ $(LOCAL_PATH)/../SDL2_ttf/ $(LOCAL_PATH)/../SDL2_mixer/ $(LOCAL_PATH)/src/Engine/coremodules/ $(LOCAL_PATH)/src/Engine/coremodules/UI $(LOCAL_PATH)/src/

# Add your application source files here...
LOCAL_SRC_FILES := main.cpp TestAnimator.cpp TestApplication.cpp TestScene.cpp TestPlayer.cpp Engine/coremodules/EActor.cpp Engine/coremodules/EAnimationClip.cpp Engine/coremodules/EAnimationController.cpp Engine/coremodules/EApplication.cpp Engine/coremodules/EAudioChunkComponent.cpp Engine/coremodules/EAudioMusicComponent.cpp Engine/coremodules/ECamera.cpp Engine/coremodules/EDebug.cpp Engine/coremodules/EGameObject.cpp Engine/coremodules/EInput.cpp Engine/coremodules/EScene.cpp Engine/coremodules/EText.cpp Engine/coremodules/ETexture.cpp Engine/coremodules/ETimer.cpp Engine/coremodules/ETransform.cpp Engine/coremodules/EUtil.cpp Engine/coremodules/EVector.cpp Engine/coremodules/EWindow.cpp Engine/coremodules/UI/EUIComponents.cpp Engine/coremodules/UI/EUIController.cpp

LOCAL_SHARED_LIBRARIES := SDL2 SDL2_image SDL2_ttf SDL2_mixer

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

LOCAL_CPPFLAGS += -std=c++11


include $(BUILD_SHARED_LIBRARY)

application.mk:

# Uncomment this if you're using STL in your project
# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information
APP_STL := stlport_static
#armeabi-v7a arm64-v8a x86 x86_64
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64

# Min runtime API level
APP_PLATFORM=android-14

build.gradle:

def buildAsLibrary = project.hasProperty('BUILD_AS_LIBRARY');
def buildAsApplication = !buildAsLibrary
if (buildAsApplication) {
    apply plugin: 'com.android.application'
}
else {
    apply plugin: 'com.android.library'
}

android {
    compileSdkVersion 19
    buildToolsVersion "26.0.1"
    defaultConfig {
        if (buildAsApplication) {
            applicationId "org.libsdl.app"
        }
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            ndkBuild {
                arguments "APP_PLATFORM=android-14"
            }
        }
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    if (!project.hasProperty('EXCLUDE_NATIVE_LIBS')) {
        sourceSets.main {
            jniLibs.srcDir 'libs'
        }

        externalNativeBuild {
            ndkBuild {
                path 'jni/Android.mk'
            }
        }

    }
    lintOptions {
        abortOnError false
    }

    if (buildAsLibrary) {
        libraryVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith(".aar")) {
                    def fileName = "org.libsdl.app.aar";
                    output.outputFile = new File(outputFile.parent, fileName);
                }
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
}

Can someone review it.

Thank you.

Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54
mrgameoz
  • 1
  • 1
  • 3
  • Which `NDK` have you downloaded ? Are you using Gradle 4.4 (plugin 3.1.2) and `Android Studio 3.1.2`? See [`NDK` manual upgrade](https://stackoverflow.com/questions/40474050/android-studio-where-to-install-ndk-file-downloaded-it-in-zip/40475804#40475804). Also see [failed to build `SDL` on Android studio](https://stackoverflow.com/questions/40474050/android-studio-where-to-install-ndk-file-downloaded-it-in-zip/40475804#40475804) – Jon Goodwin May 15 '18 at 04:51

1 Answers1

0

I have built ADL2 on theWindows platform for Android deployment using Android Studio, but I did not follow the tutorial as I already have an up-to-date Android Studio, SDK and NDK build System.

What your have shown in your question seems o.k. (much like the original project).

I did this:

  • Downloaded SDL2
  • Extracted the archive (to C:\Android\SDL2-2.0.8)
  • Imported the project android-project (from C:\Android\SDL2-2.0.8\android-project)
  • Copied (not symbolic linked) the SDL, and src diectories and Android.mk and Application.mk files to jni directory.
  • Added a main.c in the src directory with my code and put that name in Android.mk

I did not need to change anything in app level build.gradle, just the stuff you are supposed to change in the custom src directory (main.c).

I did need to update the project to Gradle 4.4 (plugin 3.1.2) because it would only build one library instead of the two in the ndkBuild (bug).

My JNI structure:

C:\Android\SDL2-2.0.8\android-project\app\jni  --+
                                                 ¦
+------------------------------------------------+
V
¦
>---Android.mk             <-----(`ndkBuild` file)
>---Application.mk         <-----(`ndkBuild` file)
¦
+---SDL
¦   +---include
¦   ¦
¦   +---src
¦       ¦
¦       +---atomic
¦       ¦
¦       +---audio
¦       ¦
¦       +---core
¦       ¦
¦       +---filesystem
¦       ¦
¦       +---haptic
¦       ¦
¦       +---joystick
¦       ¦
¦       +---libm
¦       ¦
¦       +---loadso
¦       ¦
¦       +---main
¦       ¦
¦       +---power
¦       ¦
¦       +---render
¦       ¦
¦       +---stdlib
¦       ¦
¦       +---test
¦       ¦
¦       +---timer
¦       ¦
¦       +---video         <-----`SDL_video.c` (`SDL_CreateWindow()` )
¦       
+---src                   <-----(your custom directory for `main.c`)
Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54
  • hi, ty for reply. i followed this http://lazyfoo.net/tutorials/SDL/52_hello_mobile/android_windows/index.php tutorial, the thing is i am able to run sdl sample project, the issue is not that, but my windows project which was built on sdl has many src files , and classes , it seems i am not able to link them correctly. i think i have not added correct path in android.mk, can u check the my android.mk? i am using 4.1 gradle and 3.0.1 android studio. ndk is 16.1.44 – mrgameoz May 17 '18 at 16:47
  • if u look at the image i have shared the EWindow class is inside a folder Engine/coremodules path in the src folder, so does every class which i had created. – mrgameoz May 17 '18 at 16:56
  • @mrgameoz I would suggest you run the Android build on the command line. It is often more obvious what is going on, and you cut-n-paste the output here for analysis. To do this it is simply go to the root directory of your project and use the `gradlew` script provided by `Android Studio`. You simply type `gradlew clean` then after it is finished `gradlew assembleDebug`. It should help figure out what is going on. What do you mean your `windows project`, were building for `Android` on a `Windows platform` right ? did you upgrade to latest *stuff* as I suggested ? – Jon Goodwin May 17 '18 at 17:32
  • i will try and post what u said,by windows project means, sdl supports multiplatform, the current project works fine on windows, all i am doing is trying to port it to android.. – mrgameoz May 17 '18 at 18:16
  • Cool. If you replicate your problem in a small project, all the better. – Jon Goodwin May 17 '18 at 18:23
  • Hey , i made a dummy project with sdl libs, i added all 4(SdL2,images,sound and ttf), witch source folder only containing main.cpp, with this i was able to run the build, run the app in my device. then i created a dog.h and dog.cpp (dummy classes) and boom.. [link](https://imgur.com/a/QtuMGq9) – mrgameoz May 21 '18 at 17:47
  • below is my android mk `LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := main SDL_PATH := ../SDL2 LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include $(LOCAL_PATH)/../SDL2_image/ $(LOCAL_PATH)/../SDL2_ttf/ $(LOCAL_PATH)/../SDL2_mixer/ # Add your application source files here... LOCAL_SRC_FILES := main.cpp dog.cpp LOCAL_SHARED_LIBRARIES := SDL2 SDL2_image SDL2_ttf SDL2_mixer LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog include $(BUILD_SHARED_LIBRARY) ` – mrgameoz May 21 '18 at 17:51