2015-11-06 106 views
0

我有一个使用OpenGL库和PVRTC工具的android应用程序。 此应用程序在Eclipse上运行得非常完美,直到API 19。现在我想将其移至API 23,因此认为将应用程序移植到Android Studio以及将来的更新同步。我面临的问题,在这种移植,请抬头看截图看到的文件夹层次我在Eclipse中运行代码将项目从Eclipse移植到Studio

[the project folder hierarchy


[inside the jni folder]

下面是我Android.mk文件:

LOCAL_PATH := $(call my-dir) 
PVRSDKDIR := $(LOCAL_PATH) 
include $(PVRSDKDIR)/Tools/OGLES2/Build/Android/Android.mk 
include $(CLEAR_VARS) 
LOCAL_MODULE := nativeegl 
LOCAL_CFLAGS := -DBUILD_OGLES2 -Wall -g 
LOCAL_SRC_FILES := CCAppMain.cpp 
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2# -lGLESv1_CM 
LOCAL_STATIC_LIBRARIES := \ 
          ogles2tools \ 
          android_native_app_glue 

LOCAL_C_INCLUDES := \ 
        $(PVRSDKDIR)/Builds/OGLES2/Include \ 
        $(PVRSDKDIR)/Tools \ 
        $(PVRSDKDIR)/Tools/OGLES2 
include $(BUILD_SHARED_LIBRARY) 
$(call import-module,android/native_app_glue) 

这分别是Application.mk文件在Eclipse

# The ARMv7 is significanly faster due to the use of the hardware FPU 
#APP_ABI := armeabi armeabi-v7a x86 
#APP_OPTIM := release 
APP_STL := stlport_static 

我使用过Android Studio 1.4版,摇篮内置2.5

已设置classpath中为“类路径“com.android.tools.build:gradle-experimental: 0.2.0' “

我的应用程序模块built.gradle看起来像

apply plugin: 'com.android.model.application' 
model { 
    android { 
     compileSdkVersion = 23 
     buildToolsVersion = "23.0.1" 
     defaultConfig.with { 
      applicationId = "xxx" 
      minSdkVersion.apiLevel = 14 
      targetSdkVersion.apiLevel = 23 
      versionCode = 1 
      versionName = "1.0" 
     } 
    } 
    compileOptions.with { 
     sourceCompatibility=JavaVersion.VERSION_1_7 
     targetCompatibility=JavaVersion.VERSION_1_7 
    } 
    android.ndk { 
     moduleName = "nativeegl" 
     //cppFlags += "-I${file("src/main/jni/native_app_glue")}".toString() 
     cppFlags += "-I${file("src/main/jni")}".toString() 
     cppFlags += "-I${file("src/main/jni/Tools")}".toString() 
     cppFlags += "-I${file("src/main/jni/Tools/OGLES2")}".toString() 
     cppFlags += "-I${file("src/main/jni/Tools/OGLES2/GLES2")}".toString() 
     ldLibs += ["android", "EGL", "GLESv2", "OpenSLES", "log"] 
     stl  = "stlport_static" 
    } 
    android.buildTypes { 
     release { 
      minifyEnabled = false 
      proguardFiles += file('proguard-rules.txt') 
     } 
    } 
} 
dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:support-v4:23.0.1' 
} 

我真的ñ催产素能够在此刻配置的应用程序,在同步它总是给人错误,如

Error:Execution failed for task ':app:compileArmeabi-v7aDebugNativeeglSharedLibraryNativeeglMainCpp'. 
> Multiple build operations failed. 
     C++ compiler failed while compiling PVRTPrint3D.cpp. 
     C++ compiler failed while compiling PVRTBackground.cpp. 
     C++ compiler failed while compiling PVRTShader.cpp. 
     C++ compiler failed while compiling PVRTPrint3DAPI.cpp. 
     C++ compiler failed while compiling PVRTPFXParserAPI.cpp. 
    See the complete log at: file:///E:/Android_Studio_Project/XXX/app/build/tmp/compileArmeabi-v7aDebugNativeeglSharedLibraryNativeeglMainCpp/output.txt 

任何人都可以查看一下,改正我的的build.gradle文件。我猜测PVRTC工具被忽略了。

任何帮助将不胜感激。

回答

0

你不一定要离弃你精心打造的Android.mk为实验gradle这个插件的糙米和有限的DSL。请参阅define LOCAL_SRC_FILES in ndk{} DSL

你的情况中的具体问题似乎不是PVRTC文件被忽略,而是它们没有按照在Tools/OGLES2/Build/Android/Android.mk中配置的规则和标志进行编译。

TL; NR:以下行添加到您的build.gradle

def ndkBuild = android.ndkDirectory 
import org.apache.tools.ant.taskdefs.condition.Os 
if (Os.isFamily(Os.FAMILY_WINDOWS)) { 
    ndkBuild += '.cmd' 
} 

task buildNative(type: Exec, description: 'Compile JNI source via NDK') { 
    commandLine '$ndkBuild', '-C', 'src/main' 
} 

task cleanNative(type: Exec, description: 'Clean JNI object files') { 
    commandLine '$ndkBuild', 'clean', '-C', 'src/main' 
} 

clean.dependsOn 'cleanNative' 

tasks.all { 
    task -> 
     if (task.name.startsWith('compile') && task.name.contains('MainC')) { 
      task.enabled = false 
     } 
     if (task.name.startsWith('link')) { 
      task.enabled = false 
     } 
     if (task.name.endsWith("SharedLibrary")) { 
      task.dependsOn buildNative 
     } 
} 

android { 
    sourceSets { 
     main { 
      jniLibs.srcDirs = ['src/main/libs'] 
     } 
    } 
} 
+0

所以请你告诉我正确的build.gradle NDK {} DSL,我已经在这里抛出一些答案,但无法解决它 – Sunny

+0

它的工作,但它只是看起来像解决方法,因为我无法调试NDK代码,但感谢 – Sunny

+0

@ user2207638:请检查链接[答案](http://stackoverflow.com/questions/32636150/define-local-src-files-in-ndk-dsl/32640823):我已经更新了几次,试图跟踪*实验*插入。 –