Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【igl nanovg part-1】Android : add seperate nanovg sample project #218

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
75 changes: 75 additions & 0 deletions build/android/nanovg/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

plugins {
id 'com.android.application'
}

android {
namespace 'com.facebook.igl.shell'
compileSdk 33

defaultConfig {
applicationId "com.facebook.igl.shell"
minSdk 33
targetSdk 33
versionCode 1
versionName "1.0"
ndk {
abiFilters 'arm64-v8a'
}
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('../../../CMakeLists.txt')
version '3.22.1'
}
}
buildFeatures {
viewBinding true
}

sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDir '../app/src/main/res/'

java.srcDir 'java'
java.srcDirs += ['../app/src/main/java']

assets.srcDirs += ['../../../shell/resources/images', '../../../third-party/deps/src/nanovg/example/images', '../../../third-party/deps/src/nanovg/example']
}
}

ndkVersion '25.2.9519653'
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions build/android/nanovg/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
27 changes: 27 additions & 0 deletions build/android/nanovg/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="IGLNanovg"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.IGL"
tools:targetApi="33">
<activity
android:name=".NanovgSampleActivity"
android:configChanges="orientation|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// @fb-only

package com.facebook.igl.shell;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class NanovgSampleActivity extends SampleActivity {
private static String TAG = "NanovgSampleActivity";

@Override
protected void onCreate(Bundle icicle) {
mEnableStencilBuffer = true;

super.onCreate(icicle);

boolean hasCopy = getSharedPreferences("data", Context.MODE_PRIVATE).getBoolean("HasCopyAssets", false);

if (!hasCopy) {
copyAssetsDirToSDCard(this, "", getFilesDir().getAbsolutePath());

SharedPreferences.Editor editor = getSharedPreferences("data", Context.MODE_PRIVATE).edit();
editor.putBoolean("HasCopyAssets",true);
editor.commit();
}
}

public static void copyAssetsDirToSDCard(Context context, String assetsDirName, String sdCardPath) {
Log.d(TAG, "copyAssetsDirToSDCard() called with: context = [" + context + "], assetsDirName = [" + assetsDirName + "], sdCardPath = [" + sdCardPath + "]");
try {
String list[] = context.getAssets().list(assetsDirName);
if (list.length == 0) {
InputStream inputStream = context.getAssets().open(assetsDirName);
byte[] mByte = new byte[1024];
int bt = 0;
File file = new File(sdCardPath + File.separator
+ assetsDirName);
if (!file.exists()) {
file.createNewFile();
} else {
return;
}
FileOutputStream fos = new FileOutputStream(file);
while ((bt = inputStream.read(mByte)) != -1) {
fos.write(mByte, 0, bt);
}
fos.flush();
inputStream.close();
fos.close();
} else {
String subDirName = assetsDirName;
if (assetsDirName.contains("/")) {
subDirName = assetsDirName.substring(assetsDirName.lastIndexOf('/') + 1);
}
sdCardPath = sdCardPath + File.separator + subDirName;
File file = new File(sdCardPath);
if (!file.exists())
file.mkdirs();
for (String s : list) {
String fileName = assetsDirName.length() > 0 ? assetsDirName + File.separator + s : s;
copyAssetsDirToSDCard(context, fileName , sdCardPath);
}
}
} catch (
Exception e) {
e.printStackTrace();
}
}

}
1 change: 1 addition & 0 deletions build/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencyResolutionManagement {
}
rootProject.name = "IGL"
include ':app'
include ':nanovg'
include ':app-openxr-vulkan'
include ':app-openxr-gles'

Expand Down
Loading