2015-11-06 142 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):我已經更新了幾次,試圖跟蹤*實驗*插入。 –