Undefined reference to sdl_function Android Studio

旧时模样 提交于 2019-12-13 07:57:26

问题


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:

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.


回答1:


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`)


来源:https://stackoverflow.com/questions/50200222/undefined-reference-to-sdl-function-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!