*/}}
Kaynağa Gözat

Android support

YimingWu 6 ay önce
ebeveyn
işleme
ca2f7a16af

+ 44 - 16
apk_build.cmake

@@ -17,6 +17,7 @@ list(POP_BACK ANDROID_JAR_VERSIONS ANDROID_JAR_LATEST)
 set(ANDROID_JAR "${ANDROID_JAR_LATEST}/android.jar" CACHE PATH "Path to Android JAR")
 
 set(FREETYPE_SRC_DIR "${FREETYPE_SRC_DIR}" CACHE PATH "Path to Freetype source")
+set(PNG_SRC_DIR "${PNG_SRC_DIR_SRC_DIR}" CACHE PATH "Path to PNG source")
 set(LAGUI_SRC_DIR "${LAGUI_SRC_DIR}" CACHE PATH "Path to LaGUI source")
 set(EXECUTABLE_NAME "${EXECUTABLE_NAME}" CACHE PATH "Executable name")
 set(EXECUTABLE_SRC_DIR "${EXECUTABLE_SRC_DIR}" CACHE PATH "Executable source")
@@ -38,8 +39,24 @@ macro(setup_variant VARIANT)
     -DANDROID_NDK=${ANDROID_NDK}
     -DANDROID_STL=c++_static
     -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install/${VARIANT}
-    -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
-    -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    #-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    #-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
+    BUILD_ALWAYS True
+  )
+
+  ExternalProject_Add(png-${VARIANT}
+    SOURCE_DIR ${PNG_SRC_DIR}
+    #EXCLUDE_FROM_ALL TRUE
+    CMAKE_ARGS
+    -DANDROID_ABI=${VARIANT}
+    -DANDROID_NDK=${ANDROID_NDK}
+    -DANDROID_STL=c++_static
+    -DPNG_SHARED=OFF
+    -DHAVE_LD_VERSION_SCRIPT=OFF
+    -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install/${VARIANT}
+    #-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    #-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
     -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
     BUILD_ALWAYS True
   )
@@ -53,12 +70,13 @@ macro(setup_variant VARIANT)
     -DANDROID_STL=c++_static
     -DLAGUI_USE_GLES=True
     -DLAGUI_USE_LUAJIT=False
-    -DLAGUI_USE_PNG=False
+    -DLAGUI_USE_PNG=True
     -DLAGUI_ANDROID=True
     -DFREETYPE_SRC_DIR=${FREETYPE_SRC_DIR}
+    -DPNG_SRC_DIR=${PNG_SRC_DIR}
     -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install/${VARIANT}
-    -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
-    -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    #-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    #-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
     -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
     BUILD_ALWAYS True
   )
@@ -70,20 +88,28 @@ macro(setup_variant VARIANT)
     -DANDROID_ABI=${VARIANT}
     -DANDROID_NDK=${ANDROID_NDK}
     -DANDROID_STL=c++_static
+    -DLAGUI_SRC_DIR=${LAGUI_SRC_DIR}
+    -DLAGUI_USE_GLES=True
+    -DLAGUI_USE_LUAJIT=False
+    -DLAGUI_USE_PNG=True
+    -DLAGUI_ANDROID=True
+    -DFREETYPE_SRC_DIR=${FREETYPE_SRC_DIR}
+    -DLAGUI_SRC_DIR=${LAGUI_SRC_DIR}
+    -DPNG_SRC_DIR=${PNG_SRC_DIR}
     -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install/${VARIANT}
-    #-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
-    #-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
+    -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${APK_CONTENTS_ROOT}/lib/${VARIANT}
     -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
     BUILD_ALWAYS True
     )
 
 endmacro()
 setup_variant(arm64-v8a)
-setup_variant(armeabi-v7a)
-setup_variant(x86)
+#setup_variant(armeabi-v7a)
+#setup_variant(x86)
 setup_variant(x86_64)
 
-set(MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml")
+set(MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/src/AndroidManifest.xml")
 set(RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/res")
 set(KEYSTORE "${CMAKE_CURRENT_SOURCE_DIR}/keystore.jks")
 
@@ -112,14 +138,16 @@ add_custom_command(
   WORKING_DIRECTORY ${APK_CONTENTS_ROOT}
   DEPENDS
     ${RESOURCES_APK}
-    ${PROJECT_NAME}-armeabi-v7a
-    ${PROJECT_NAME}-arm64-v8a
-    ${PROJECT_NAME}-x86
-    ${PROJECT_NAME}-x86_64
+    #${EXECUTABLE_NAME}-armeabi-v7a
+    ${EXECUTABLE_NAME}-arm64-v8a
+    #${EXECUTABLE_NAME}-x86
+    ${EXECUTABLE_NAME}-x86_64
     freetype-x86_64
-    freetype-x86
+    #freetype-x86
     freetype-arm64-v8a
-    freetype-armeabi-v7a
+    #freetype-armeabi-v7a
+    png-x86_64
+    png-arm64-v8a
   )
 add_custom_command(
   OUTPUT ${FINAL_APK}

BIN
res/mipmap-hdpi/ic_launcher.png


BIN
res/mipmap-mdpi/ic_launcher.png


BIN
res/mipmap-xhdpi/ic_launcher.png


BIN
res/mipmap-xxhdpi/ic_launcher.png


+ 4 - 0
res/values/strings.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Hello LaGUI</string>
+</resources>

+ 4 - 2
src/AndroidManifest.xml

@@ -5,7 +5,9 @@
   android:versionName="1.0">
 
   <uses-sdk android:minSdkVersion="26"/>
-  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
+  <uses-feature android:glEsVersion="0x00030000" android:required="true" />
+  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
+  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
 
   <!-- This .apk has no Java code itself, so set hasCode to false. -->
   <!-- android:icon="@mipmap/ic_launcher" --> 
@@ -22,7 +24,7 @@
       android:launchMode="singleTask">
 
       <!-- Tell NativeActivity the name of our .so -->
-      <meta-data android:name="android.app.lib_name" android:value="hello-world" />
+      <meta-data android:name="android.app.lib_name" android:value="hello-android" />
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />

+ 26 - 3
src/CMakeLists.txt

@@ -1,13 +1,36 @@
 cmake_minimum_required(VERSION 3.17)
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-project(hello-world)
+project(hello-android)
+
+if(${LAGUI_ANDROID})
+    add_definitions(-DLAGUI_ANDROID)
+endif()
 
 INCLUDE_DIRECTORIES(${FREETYPE_SRC_DIR}/include)
 INCLUDE_DIRECTORIES(${LAGUI_SRC_DIR})
+INCLUDE_DIRECTORIES(${LAGUI_SRC_DIR}/nanovg)
+INCLUDE_DIRECTORIES(${PNG_SRC_DIR})
 INCLUDE_DIRECTORIES(${ANDROID_NDK}/sources/android/native_app_glue)
 
+if(${LAGUI_USE_PNG})
+    add_definitions(-DLA_WITH_PNG)
+endif()
+
 LINK_DIRECTORIES(../build/install/${ANDROID_ABI}/lib)
+LINK_DIRECTORIES(../build/install/${ANDROID_ABI}/lib/lagui)
+
+add_library(${PROJECT_NAME} SHARED hello_android.c ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
+
+if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
+set(GLLIBVER GLESv2)
+else()
+set(GLLIBVER GLESv3)
+endif()
+
+target_link_libraries(${PROJECT_NAME} PUBLIC log lagui ${GLLIBVER} EGL android z png freetype)
+
+
+target_link_options(${PROJECT_NAME} BEFORE PUBLIC "-Wl,--start-group")
+target_link_options(${PROJECT_NAME} PUBLIC "-Wl,--end-group")
 
-add_library(${PROJECT_NAME} SHARED main.cpp ${ANDROID_NDK}sources/android/native_app_glue/android_native_app_glue.c)
-target_link_libraries(${PROJECT_NAME} PUBLIC log GLESv2 EGL android freetype z lagui)
 install(TARGETS ${PROJECT_NAME})

+ 4 - 1
src/hello_android.c

@@ -18,12 +18,15 @@
 
 #include "la_5.h"
 
+extern LA MAIN;
+
 void MyPanel(laUiList *uil, laPropPack *This, laPropPack *DetachedProps, laColumn *UNUSED, int context){
     laColumn* c=laFirstColumn(uil);
     laShowLabel(uil,c,"Hello world!",0,0);
 }
 
 int main(int argc, char *argv[]){
+    laSetFontFolderPath(".");
     laGetReady();
 
     transSetLanguage("zh-CN");
@@ -32,7 +35,7 @@ int main(int argc, char *argv[]){
 
     laWindow* w = laDesignWindow(-1,-1,600,600);
     laLayout* l = laDesignLayout(w,"My Layout");
-    laCreatePanel(l->FirstBlock,"my_panel");
+    laCreatePanel(l->FirstBlock,"LAUI_about");
 
     laStartWindow(w);
     laMainLoop();