未定义对sdl_function Android Studio的引用 [英] Undefined reference to sdl_function Android Studio

查看:105
本文介绍了未定义对sdl_function Android Studio的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Android上运行sd l游戏,我按照lazyfoo's教程运行helloworld,效果很好,后来我导入了我的项目,该项目源在Windows中运行正常,没有任何错误,但是我现在在文件中看到许多错误,我是android的新手,我觉得自己已经把源文件的路径弄乱了.下面是错误:

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 (在src目录中):

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'
}

有人可以查看它吗.

谢谢.

推荐答案

我已经在Windows平台上使用Android StudioWindows平台上构建了ADL2,用于Android部署,但是我没有按照教程进行操作,因为我已经掌握了-最新的Android StudioSDKNDK构建系统.

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

我这样做了:

  • 下载的SDL2
  • 提取存档文件(至C:\Android\SDL2-2.0.8)
  • 导入了项目android-project(来自C:\Android\SDL2-2.0.8\android-project)
  • 复制(未符号链接)将SDL,src目录以及Android.mkApplication.mk文件复制到jni目录.
  • 使用我的代码在src目录中添加了main.c并将该名称放置在Android.mk
  • 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

我不需要在应用程序级别build.gradle中进行任何更改,只需要更改自定义src目录(main.c)中的内容即可.

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

我确实需要将项目更新为Gradle 4.4(plugin 3.1.2),因为它只会构建一个库,而不是ndkBuild(错误)中的两个库.

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

我的JNI结构:

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

这篇关于未定义对sdl_function Android Studio的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆