├── .gitignore ├── LICENSE.TXT ├── README.md ├── build-app ├── GL2 │ ├── README.md │ ├── app │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── cpp │ │ │ ├── Android.mk │ │ │ ├── Application.mk │ │ │ ├── CMakeLists.txt │ │ │ └── gl_code.cpp │ │ │ ├── java │ │ │ └── com │ │ │ │ └── android │ │ │ │ └── gl2 │ │ │ │ ├── GL2JNIActivity.java │ │ │ │ ├── GL2JNILib.java │ │ │ │ └── GL2JNIView.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ └── strings.xml │ ├── build.gradle │ ├── gles2.jpg │ ├── gradlew │ ├── gradlew.bat │ ├── local.properties │ └── settings.gradle ├── GL3 │ ├── README.md │ ├── app │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── cpp │ │ │ ├── Android.mk │ │ │ ├── Application.mk │ │ │ ├── CMakeLists.txt │ │ │ ├── RendererES2.cpp │ │ │ ├── RendererES3.cpp │ │ │ ├── gl3stub.c │ │ │ ├── gl3stub.h │ │ │ ├── gles3jni.cpp │ │ │ └── gles3jni.h │ │ │ ├── java │ │ │ └── com │ │ │ │ └── android │ │ │ │ └── gles3 │ │ │ │ ├── GLES3JNIActivity.java │ │ │ │ ├── GLES3JNILib.java │ │ │ │ └── GLES3JNIView.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ └── strings.xml │ ├── build.gradle │ ├── gles3.jpg │ ├── gradlew │ ├── gradlew.bat │ ├── local.properties │ └── settings.gradle ├── README.md ├── rust-example │ ├── .gitignore │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle.kts │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── rust │ │ │ │ └── example │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.webp │ │ │ └── ic_launcher_round.webp │ │ │ ├── values-night │ │ │ ├── colors.xml │ │ │ └── themes.xml │ │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ │ └── xml │ │ │ ├── backup_rules.xml │ │ │ └── data_extraction_rules.xml │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradlew │ ├── gradlew.bat │ ├── local.properties │ ├── rust │ │ ├── .gitignore │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ └── settings.gradle.kts └── screenshot │ ├── build_termux_app1.jpg │ └── build_termux_app2.jpg ├── docs ├── .gitignore ├── Architecture.md ├── BuildSystemMaintainers.md ├── Building.md ├── ClangMigration.md ├── ContinuousBuilds.md ├── HardFloatAbi.md ├── Makefile ├── NdkGdbTesting.md ├── Onboarding.md ├── PlatformApis.md ├── Roadmap.md ├── Testing.md ├── Toolchains.md ├── UnifiedHeaders.md ├── UnifiedHeadersMigration.md ├── UpdatingDocumentation.md ├── changelogs │ ├── Changelog-r19.md │ ├── Changelog-r20.md │ ├── Changelog-r21.md │ ├── Changelog-r22.md │ ├── Changelog-r23.md │ ├── Changelog-r24.md │ ├── Changelog-r25.md │ ├── Changelog-r26.md │ └── Changelog-r27.md ├── repo.md └── user │ ├── common_problems.md │ └── middleware_vendors.md └── patches ├── cmake ├── Android-Clang.cmake.patch ├── Android-Determine.cmake.patch ├── Android-Initialize.cmake.patch ├── Android.cmake.patch └── Determine-Compiler.cmake.patch ├── crypt.h ├── llvm_android ├── base_builders.py.patch ├── builders.py.patch ├── configs.py.patch └── paths.py.patch ├── llvm_project ├── Editline.h.patch ├── IOHandlerCursesGUI.cpp.patch └── vis.c.patch └── ndk ├── android-legacy.toolchain.cmake.patch ├── android.toolchain.cmake.patch ├── autoconf.py.patch ├── checkbuild.py.patch ├── ndk_bin_common.sh.patch └── toolchains.py.patch /.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /build 3 | git_remove_history.sh -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Android ndk for Termux(only supports aarch64 and Android 9 or above)** 2 | 3 | The source code from AOSP [llvm-toolchain](https://android.googlesource.com/toolchain/llvm-project), which is consistent with the official NDK version. 4 | 5 | At first, we don‘t need to rebuild the whole NDK, since google already built most of it. 6 | so we only need to build the llvm toolchain, then replace the llvm inside NDK. 7 | 8 | Building the `android-ndk`, please refer to [Android Clang/LLVM Toolchain Readme Doc](https://android.googlesource.com/toolchain/llvm_android/+/master/README.md) 9 | 10 | Packaging and testing the `android-ndk`, please refer to [Ndk Toolchains Readme Doc](https://android.googlesource.com/platform/ndk/+/refs/heads/main/docs/Building.md) 11 | 12 | Building `android app` with termux-ndk, please refer to [build-app](https://github.com/Lzhiyong/termux-ndk/tree/master/build-app) 13 | -------------------------------------------------------------------------------- /build-app/GL2/README.md: -------------------------------------------------------------------------------- 1 | Hello GL2 2 | ========= 3 | Hello GL2 is an Android C++ sample that draws a triangle using GLES 2.0 API. 4 | 5 | It uses JNI to do the rendering in C++ over a 6 | [GLSurfaceView](http://developer.android.com/reference/android/opengl/GLSurfaceView.html) 7 | created from a regular Android Java Activity. 8 | 9 | This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support. 10 | 11 | Pre-requisites 12 | -------------- 13 | - Android Studio 2.2 preview+ with [NDK](https://developer.android.com/ndk/) bundle. 14 | 15 | Getting Started 16 | --------------- 17 | 1. [Download Android Studio](http://developer.android.com/sdk/index.html) 18 | 1. Launch Android Studio. 19 | 1. Open the sample directory. 20 | 1. Open *File/Project Structure...* 21 | - Click *Download* or *Select NDK location*. 22 | 1. Click *Tools/Android/Sync Project with Gradle Files*. 23 | 1. Click *Run/Run 'app'*. 24 | 25 | Screenshots 26 | ----------- 27 | ![screenshot](gles2.jpg) 28 | 29 | Support 30 | ------- 31 | If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new). 32 | 33 | Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and 34 | submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details. 35 | 36 | - [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk) 37 | - [Android Tools Feedbacks](http://tools.android.com/feedback) 38 | 39 | License 40 | ------- 41 | Copyright 2015 Google, Inc. 42 | 43 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 44 | license agreements. See the NOTICE file distributed with this work for 45 | additional information regarding copyright ownership. The ASF licenses this 46 | file to you under the Apache License, Version 2.0 (the "License"); you may not 47 | use this file except in compliance with the License. You may obtain a copy of 48 | the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 54 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 55 | License for the specific language governing permissions and limitations under 56 | the License. 57 | -------------------------------------------------------------------------------- /build-app/GL2/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 31 5 | buildToolsVersion "35.0.0" 6 | namespace = "com.android.gles2" 7 | 8 | defaultConfig { 9 | applicationId 'com.android.gl2' 10 | minSdkVersion 21 11 | targetSdkVersion 28 12 | externalNativeBuild { 13 | cmake { 14 | // Available arguments are inside ${SDK}/cmake/.../android.toolchain.cmake file 15 | arguments '-DANDROID_STL=c++_static' 16 | } 17 | } 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled = false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 24 | 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | externalNativeBuild { 29 | cmake { 30 | version '3.18.5+' 31 | path 'src/main/cpp/CMakeLists.txt' 32 | } 33 | } 34 | 35 | //externalNativeBuild { 36 | // ndkBuild { 37 | // path 'src/main/cpp/Android.mk' 38 | // } 39 | //} 40 | } 41 | -------------------------------------------------------------------------------- /build-app/GL2/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/cpp/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_CPP_EXTENSION := .cpp .cc 20 | LOCAL_CFLAGS += -Wall 21 | LOCAL_CPPFLAGS += -std=c++11 -Wall 22 | 23 | LOCAL_MODULE := gl2 24 | LOCAL_SRC_FILES := gl_code.cpp 25 | 26 | ifeq ($(TARGET_ARCH_ABI),x86) 27 | LOCAL_CFLAGS += -ffast-math -mtune=atom -mssse3 -mfpmath=sse 28 | endif 29 | 30 | LOCAL_LDLIBS := -lGLESv2 -lEGL -llog -landroid 31 | 32 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/cpp/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := all 2 | APP_STL := c++_static 3 | APP_PLATFORM := android-28 -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14.2) 2 | 3 | # now build app's shared lib 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") 5 | 6 | add_library(gl2 SHARED gl_code.cpp) 7 | 8 | # add lib dependencies 9 | target_link_libraries(gl2 10 | android 11 | log 12 | EGL 13 | GLESv2) 14 | 15 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/cpp/gl_code.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // OpenGL ES 2.0 code 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define LOG_TAG "libgl2jni" 30 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 31 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 32 | 33 | static void printGLString(const char *name, GLenum s) { 34 | const char *v = (const char *) glGetString(s); 35 | LOGI("GL %s = %s\n", name, v); 36 | } 37 | 38 | static void checkGlError(const char* op) { 39 | for (GLint error = glGetError(); error; error 40 | = glGetError()) { 41 | LOGI("after %s() glError (0x%x)\n", op, error); 42 | } 43 | } 44 | 45 | auto gVertexShader = 46 | "attribute vec4 vPosition;\n" 47 | "void main() {\n" 48 | " gl_Position = vPosition;\n" 49 | "}\n"; 50 | 51 | auto gFragmentShader = 52 | "precision mediump float;\n" 53 | "void main() {\n" 54 | " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" 55 | "}\n"; 56 | 57 | GLuint loadShader(GLenum shaderType, const char* pSource) { 58 | GLuint shader = glCreateShader(shaderType); 59 | if (shader) { 60 | glShaderSource(shader, 1, &pSource, NULL); 61 | glCompileShader(shader); 62 | GLint compiled = 0; 63 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); 64 | if (!compiled) { 65 | GLint infoLen = 0; 66 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); 67 | if (infoLen) { 68 | char* buf = (char*) malloc(infoLen); 69 | if (buf) { 70 | glGetShaderInfoLog(shader, infoLen, NULL, buf); 71 | LOGE("Could not compile shader %d:\n%s\n", 72 | shaderType, buf); 73 | free(buf); 74 | } 75 | glDeleteShader(shader); 76 | shader = 0; 77 | } 78 | } 79 | } 80 | return shader; 81 | } 82 | 83 | GLuint createProgram(const char* pVertexSource, const char* pFragmentSource) { 84 | GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource); 85 | if (!vertexShader) { 86 | return 0; 87 | } 88 | 89 | GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource); 90 | if (!pixelShader) { 91 | return 0; 92 | } 93 | 94 | GLuint program = glCreateProgram(); 95 | if (program) { 96 | glAttachShader(program, vertexShader); 97 | checkGlError("glAttachShader"); 98 | glAttachShader(program, pixelShader); 99 | checkGlError("glAttachShader"); 100 | glLinkProgram(program); 101 | GLint linkStatus = GL_FALSE; 102 | glGetProgramiv(program, GL_LINK_STATUS, &linkStatus); 103 | if (linkStatus != GL_TRUE) { 104 | GLint bufLength = 0; 105 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength); 106 | if (bufLength) { 107 | char* buf = (char*) malloc(bufLength); 108 | if (buf) { 109 | glGetProgramInfoLog(program, bufLength, NULL, buf); 110 | LOGE("Could not link program:\n%s\n", buf); 111 | free(buf); 112 | } 113 | } 114 | glDeleteProgram(program); 115 | program = 0; 116 | } 117 | } 118 | return program; 119 | } 120 | 121 | GLuint gProgram; 122 | GLuint gvPositionHandle; 123 | 124 | bool setupGraphics(int w, int h) { 125 | printGLString("Version", GL_VERSION); 126 | printGLString("Vendor", GL_VENDOR); 127 | printGLString("Renderer", GL_RENDERER); 128 | printGLString("Extensions", GL_EXTENSIONS); 129 | 130 | LOGI("setupGraphics(%d, %d)", w, h); 131 | gProgram = createProgram(gVertexShader, gFragmentShader); 132 | if (!gProgram) { 133 | LOGE("Could not create program."); 134 | return false; 135 | } 136 | gvPositionHandle = glGetAttribLocation(gProgram, "vPosition"); 137 | checkGlError("glGetAttribLocation"); 138 | LOGI("glGetAttribLocation(\"vPosition\") = %d\n", 139 | gvPositionHandle); 140 | 141 | glViewport(0, 0, w, h); 142 | checkGlError("glViewport"); 143 | return true; 144 | } 145 | 146 | const GLfloat gTriangleVertices[] = { 0.0f, 0.5f, -0.5f, -0.5f, 147 | 0.5f, -0.5f }; 148 | 149 | void renderFrame() { 150 | static float grey; 151 | grey += 0.01f; 152 | if (grey > 1.0f) { 153 | grey = 1.0f; 154 | } 155 | glClearColor(grey, grey, grey, 1.0f); 156 | checkGlError("glClearColor"); 157 | glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 158 | checkGlError("glClear"); 159 | 160 | glUseProgram(gProgram); 161 | checkGlError("glUseProgram"); 162 | 163 | glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices); 164 | checkGlError("glVertexAttribPointer"); 165 | glEnableVertexAttribArray(gvPositionHandle); 166 | checkGlError("glEnableVertexAttribArray"); 167 | glDrawArrays(GL_TRIANGLES, 0, 3); 168 | checkGlError("glDrawArrays"); 169 | } 170 | 171 | extern "C" { 172 | JNIEXPORT void JNICALL Java_com_android_gl2_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height); 173 | JNIEXPORT void JNICALL Java_com_android_gl2_GL2JNILib_step(JNIEnv * env, jobject obj); 174 | }; 175 | 176 | JNIEXPORT void JNICALL Java_com_android_gl2_GL2JNILib_init(JNIEnv * env, jobject obj, jint width, jint height) 177 | { 178 | setupGraphics(width, height); 179 | } 180 | 181 | JNIEXPORT void JNICALL Java_com_android_gl2_GL2JNILib_step(JNIEnv * env, jobject obj) 182 | { 183 | renderFrame(); 184 | } 185 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/java/com/android/gl2/GL2JNIActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.gl2; 18 | 19 | import android.app.Activity; 20 | import android.os.Bundle; 21 | import android.util.Log; 22 | import android.view.WindowManager; 23 | 24 | import java.io.File; 25 | 26 | 27 | public class GL2JNIActivity extends Activity { 28 | 29 | GL2JNIView mView; 30 | 31 | @Override protected void onCreate(Bundle icicle) { 32 | super.onCreate(icicle); 33 | mView = new GL2JNIView(getApplication()); 34 | setContentView(mView); 35 | } 36 | 37 | @Override protected void onPause() { 38 | super.onPause(); 39 | mView.onPause(); 40 | } 41 | 42 | @Override protected void onResume() { 43 | super.onResume(); 44 | mView.onResume(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/java/com/android/gl2/GL2JNILib.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.gl2; 18 | 19 | // Wrapper for native library 20 | 21 | public class GL2JNILib { 22 | 23 | static { 24 | System.loadLibrary("gl2"); 25 | } 26 | 27 | /** 28 | * @param width the current view width 29 | * @param height the current view height 30 | */ 31 | public static native void init(int width, int height); 32 | public static native void step(); 33 | } 34 | -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL2/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL2/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL2/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL2/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 23 | 24 | 25 | 26 | GL2 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /build-app/GL2/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:8.6.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build-app/GL2/gles2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL2/gles2.jpg -------------------------------------------------------------------------------- /build-app/GL2/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /build-app/GL2/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /build-app/GL2/local.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | 7 | # location of the SDK. This is only used by Ant 8 | # For customization when using a Version Control System, please read the 9 | # header note 10 | 11 | # android-sdk location 12 | sdk.dir=/data/data/com.termux/files/home/opt/android-sdk 13 | 14 | # android-ndk location 15 | ndk.dir=/data/data/com.termux/files/home/opt/android-ndk-r27b 16 | 17 | # cmake location 18 | cmake.dir=/data/data/com.termux/files/home/opt/android-sdk/cmake 19 | -------------------------------------------------------------------------------- /build-app/GL2/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /build-app/GL3/README.md: -------------------------------------------------------------------------------- 1 | gles3 2 | ========= 3 | gles3 is an Android C++ sample that demonstrates how to use OpenGL ES 3.0 from JNI/native code. 4 | 5 | The OpenGL ES 3.0 rendering path uses a few new features compared to the 6 | OpenGL ES 2.0 path: 7 | - Instanced rendering and vertex attribute divisor to reduce the number of 8 | draw calls and uniform changes. 9 | - Vertex array objects to reduce the number of calls required to set up 10 | vertex attribute state on each frame. 11 | - Explicit assignment of attribute locations, eliminating the need to query 12 | assignments. 13 | 14 | This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support. 15 | 16 | Pre-requisites 17 | -------------- 18 | - Android Studio 1.3+ with [NDK](https://developer.android.com/ndk/) bundle. 19 | 20 | Getting Started 21 | --------------- 22 | 1. [Download Android Studio](http://developer.android.com/sdk/index.html) 23 | 1. Launch Android Studio. 24 | 1. Open the sample directory. 25 | 1. Open *File/Project Structure...* 26 | - Click *Download* or *Select NDK location*. 27 | 1. Click *Tools/Android/Sync Project with Gradle Files*. 28 | 1. Click *Run/Run 'app'*. 29 | 30 | Screenshots 31 | ----------- 32 | ![screenshot](gles3.jpg) 33 | 34 | Support 35 | ------- 36 | If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new). 37 | 38 | Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and 39 | submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details. 40 | 41 | - [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk) 42 | - [Android Tools Feedbacks](http://tools.android.com/feedback) 43 | 44 | License 45 | ------- 46 | Copyright 2015 Google, Inc. 47 | 48 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 49 | license agreements. See the NOTICE file distributed with this work for 50 | additional information regarding copyright ownership. The ASF licenses this 51 | file to you under the Apache License, Version 2.0 (the "License"); you may not 52 | use this file except in compliance with the License. You may obtain a copy of 53 | the License at 54 | 55 | http://www.apache.org/licenses/LICENSE-2.0 56 | 57 | Unless required by applicable law or agreed to in writing, software 58 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 59 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 60 | License for the specific language governing permissions and limitations under 61 | the License. 62 | -------------------------------------------------------------------------------- /build-app/GL3/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | def platformVersion = 24 // openGLES 3.2 min api level 4 | // def platformVersion = 18 //openGLES 3 min api level 5 | // def platformVersion = 12 //openGLES 2 min api level 6 | 7 | android { 8 | compileSdkVersion 31 9 | buildToolsVersion "35.0.0" 10 | namespace = "com.android.gles3" 11 | 12 | defaultConfig { 13 | applicationId 'com.android.gles3' 14 | minSdkVersion "${platformVersion}" 15 | targetSdkVersion 28 16 | 17 | externalNativeBuild { 18 | cmake { 19 | arguments '-DANDROID_STL=c++_static' 20 | } 21 | } 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled = false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 28 | 'proguard-rules.pro' 29 | } 30 | } 31 | 32 | //externalNativeBuild { 33 | // cmake { 34 | // version '3.18.5+' 35 | // path 'src/main/cpp/CMakeLists.txt' 36 | // } 37 | //} 38 | 39 | externalNativeBuild { 40 | ndkBuild { 41 | path 'src/main/cpp/Android.mk' 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /build-app/GL3/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_CPP_EXTENSION := .cpp .cc 20 | LOCAL_CFLAGS += -Wall 21 | LOCAL_CPPFLAGS += -std=c++11 -fno-rtti -fno-exceptions -Wall 22 | 23 | LOCAL_MODULE := gles3 24 | LOCAL_SRC_FILES := gles3jni.cpp \ 25 | RendererES2.cpp \ 26 | RendererES3.cpp 27 | 28 | ifeq ($(TARGET_ARCH_ABI),x86) 29 | LOCAL_CFLAGS += -ffast-math -mtune=atom -mssse3 -mfpmath=sse 30 | endif 31 | 32 | LOCAL_LDLIBS := -lGLESv3 -lEGL -landroid -llog 33 | 34 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := all 2 | APP_STL := c++_static 3 | APP_PLATFORM := android-28 -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14.2) 2 | # set targetPlatform, will be passed in from gradle when this sample is completed 3 | # openGL Supportability 4 | # platform status 5 | # (0 12) ES2/ES3 not supported 6 | # [12, 18) ES2 only; for ES3, app do dynamic load/detection 7 | # this applies to the situations that: 8 | # - minimum API is set to less than 18. In this case 9 | # there is no ES3 header/lib support inside NDK 10 | # - the built APK might be running on newer API phones 11 | # with dynamic loading of ES3, the same APK would still be able 12 | # to use ES3. Otherwise, app would stuck with ES2 even phone is 13 | # is newer than the minimum API level (for example, Android-27 etc). 14 | # 15 | # [18, 24) ES2 & ES3 16 | # If app is built to only support API-18 or later, 17 | # set minimum api level to 18 is good enough, NDK supprts ES3 18 | # with the right header and lib files. No need to use ES3 dynamic 19 | # detection. 20 | # [24, infinite) ES2 & ES3 & Vulkan 21 | 22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -Wall") 24 | if (${ANDROID_PLATFORM_LEVEL} LESS 12) 25 | message(FATAL_ERROR "OpenGL 2 is not supported before API level 11 \ 26 | (currently using ${ANDROID_PLATFORM_LEVEL}).") 27 | return() 28 | elseif (${ANDROID_PLATFORM_LEVEL} LESS 18) 29 | add_definitions("-DDYNAMIC_ES3") 30 | set(GL3STUB_SRC gl3stub.c) 31 | set(OPENGL_LIB GLESv2) 32 | else () 33 | set(OPENGL_LIB GLESv3) 34 | endif (${ANDROID_PLATFORM_LEVEL} LESS 12) 35 | 36 | add_library(gles3 SHARED 37 | ${GL3STUB_SRC} 38 | gles3jni.cpp 39 | RendererES2.cpp 40 | RendererES3.cpp) 41 | 42 | # Include libraries needed for gles3 lib 43 | target_link_libraries(gles3 44 | ${OPENGL_LIB} 45 | android 46 | EGL 47 | log) 48 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/RendererES2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "gles3jni.h" 18 | #include 19 | 20 | static const char VERTEX_SHADER[] = 21 | "#version 100\n" 22 | "uniform mat2 scaleRot;\n" 23 | "uniform vec2 offset;\n" 24 | "attribute vec2 pos;\n" 25 | "attribute vec4 color;\n" 26 | "varying vec4 vColor;\n" 27 | "void main() {\n" 28 | " gl_Position = vec4(scaleRot*pos + offset, 0.0, 1.0);\n" 29 | " vColor = color;\n" 30 | "}\n"; 31 | 32 | static const char FRAGMENT_SHADER[] = 33 | "#version 100\n" 34 | "precision mediump float;\n" 35 | "varying vec4 vColor;\n" 36 | "void main() {\n" 37 | " gl_FragColor = vColor;\n" 38 | "}\n"; 39 | 40 | class RendererES2: public Renderer { 41 | public: 42 | RendererES2(); 43 | virtual ~RendererES2(); 44 | bool init(); 45 | 46 | private: 47 | virtual float* mapOffsetBuf(); 48 | virtual void unmapOffsetBuf(); 49 | virtual float* mapTransformBuf(); 50 | virtual void unmapTransformBuf(); 51 | virtual void draw(unsigned int numInstances); 52 | 53 | const EGLContext mEglContext; 54 | GLuint mProgram; 55 | GLuint mVB; 56 | GLint mPosAttrib; 57 | GLint mColorAttrib; 58 | GLint mScaleRotUniform; 59 | GLint mOffsetUniform; 60 | 61 | float mOffsets[2*MAX_INSTANCES]; 62 | float mScaleRot[4*MAX_INSTANCES]; // array of 2x2 column-major matrices 63 | }; 64 | 65 | Renderer* createES2Renderer() { 66 | RendererES2* renderer = new RendererES2; 67 | if (!renderer->init()) { 68 | delete renderer; 69 | return NULL; 70 | } 71 | return renderer; 72 | } 73 | 74 | RendererES2::RendererES2() 75 | : mEglContext(eglGetCurrentContext()), 76 | mProgram(0), 77 | mVB(0), 78 | mPosAttrib(-1), 79 | mColorAttrib(-1), 80 | mScaleRotUniform(-1), 81 | mOffsetUniform(-1) 82 | {} 83 | 84 | bool RendererES2::init() { 85 | mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER); 86 | if (!mProgram) 87 | return false; 88 | mPosAttrib = glGetAttribLocation(mProgram, "pos"); 89 | mColorAttrib = glGetAttribLocation(mProgram, "color"); 90 | mScaleRotUniform = glGetUniformLocation(mProgram, "scaleRot"); 91 | mOffsetUniform = glGetUniformLocation(mProgram, "offset"); 92 | 93 | glGenBuffers(1, &mVB); 94 | glBindBuffer(GL_ARRAY_BUFFER, mVB); 95 | glBufferData(GL_ARRAY_BUFFER, sizeof(QUAD), &QUAD[0], GL_STATIC_DRAW); 96 | 97 | ALOGV("Using OpenGL ES 2.0 renderer"); 98 | return true; 99 | } 100 | 101 | RendererES2::~RendererES2() { 102 | /* The destructor may be called after the context has already been 103 | * destroyed, in which case our objects have already been destroyed. 104 | * 105 | * If the context exists, it must be current. This only happens when we're 106 | * cleaning up after a failed init(). 107 | */ 108 | if (eglGetCurrentContext() != mEglContext) 109 | return; 110 | glDeleteBuffers(1, &mVB); 111 | glDeleteProgram(mProgram); 112 | } 113 | 114 | float* RendererES2::mapOffsetBuf() { 115 | return mOffsets; 116 | } 117 | 118 | void RendererES2::unmapOffsetBuf() { 119 | } 120 | 121 | float* RendererES2::mapTransformBuf() { 122 | return mScaleRot; 123 | } 124 | 125 | void RendererES2::unmapTransformBuf() { 126 | } 127 | 128 | void RendererES2::draw(unsigned int numInstances) { 129 | glUseProgram(mProgram); 130 | 131 | glBindBuffer(GL_ARRAY_BUFFER, mVB); 132 | glVertexAttribPointer(mPosAttrib, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, pos)); 133 | glVertexAttribPointer(mColorAttrib, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, rgba)); 134 | glEnableVertexAttribArray(mPosAttrib); 135 | glEnableVertexAttribArray(mColorAttrib); 136 | 137 | for (unsigned int i = 0; i < numInstances; i++) { 138 | glUniformMatrix2fv(mScaleRotUniform, 1, GL_FALSE, mScaleRot + 4*i); 139 | glUniform2fv(mOffsetUniform, 1, mOffsets + 2*i); 140 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/RendererES3.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "gles3jni.h" 18 | #include 19 | 20 | #define STR(s) #s 21 | #define STRV(s) STR(s) 22 | 23 | #define POS_ATTRIB 0 24 | #define COLOR_ATTRIB 1 25 | #define SCALEROT_ATTRIB 2 26 | #define OFFSET_ATTRIB 3 27 | 28 | static const char VERTEX_SHADER[] = 29 | "#version 300 es\n" 30 | "layout(location = " STRV(POS_ATTRIB) ") in vec2 pos;\n" 31 | "layout(location=" STRV(COLOR_ATTRIB) ") in vec4 color;\n" 32 | "layout(location=" STRV(SCALEROT_ATTRIB) ") in vec4 scaleRot;\n" 33 | "layout(location=" STRV(OFFSET_ATTRIB) ") in vec2 offset;\n" 34 | "out vec4 vColor;\n" 35 | "void main() {\n" 36 | " mat2 sr = mat2(scaleRot.xy, scaleRot.zw);\n" 37 | " gl_Position = vec4(sr*pos + offset, 0.0, 1.0);\n" 38 | " vColor = color;\n" 39 | "}\n"; 40 | 41 | static const char FRAGMENT_SHADER[] = 42 | "#version 300 es\n" 43 | "precision mediump float;\n" 44 | "in vec4 vColor;\n" 45 | "out vec4 outColor;\n" 46 | "void main() {\n" 47 | " outColor = vColor;\n" 48 | "}\n"; 49 | 50 | class RendererES3: public Renderer { 51 | public: 52 | RendererES3(); 53 | virtual ~RendererES3(); 54 | bool init(); 55 | 56 | private: 57 | enum {VB_INSTANCE, VB_SCALEROT, VB_OFFSET, VB_COUNT}; 58 | 59 | virtual float* mapOffsetBuf(); 60 | virtual void unmapOffsetBuf(); 61 | virtual float* mapTransformBuf(); 62 | virtual void unmapTransformBuf(); 63 | virtual void draw(unsigned int numInstances); 64 | 65 | const EGLContext mEglContext; 66 | GLuint mProgram; 67 | GLuint mVB[VB_COUNT]; 68 | GLuint mVBState; 69 | }; 70 | 71 | Renderer* createES3Renderer() { 72 | RendererES3* renderer = new RendererES3; 73 | if (!renderer->init()) { 74 | delete renderer; 75 | return NULL; 76 | } 77 | return renderer; 78 | } 79 | 80 | RendererES3::RendererES3() 81 | : mEglContext(eglGetCurrentContext()), 82 | mProgram(0), 83 | mVBState(0) 84 | { 85 | for (int i = 0; i < VB_COUNT; i++) 86 | mVB[i] = 0; 87 | } 88 | 89 | bool RendererES3::init() { 90 | mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER); 91 | if (!mProgram) 92 | return false; 93 | 94 | glGenBuffers(VB_COUNT, mVB); 95 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_INSTANCE]); 96 | glBufferData(GL_ARRAY_BUFFER, sizeof(QUAD), &QUAD[0], GL_STATIC_DRAW); 97 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_SCALEROT]); 98 | glBufferData(GL_ARRAY_BUFFER, MAX_INSTANCES * 4*sizeof(float), NULL, GL_DYNAMIC_DRAW); 99 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_OFFSET]); 100 | glBufferData(GL_ARRAY_BUFFER, MAX_INSTANCES * 2*sizeof(float), NULL, GL_STATIC_DRAW); 101 | 102 | glGenVertexArrays(1, &mVBState); 103 | glBindVertexArray(mVBState); 104 | 105 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_INSTANCE]); 106 | glVertexAttribPointer(POS_ATTRIB, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, pos)); 107 | glVertexAttribPointer(COLOR_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (const GLvoid*)offsetof(Vertex, rgba)); 108 | glEnableVertexAttribArray(POS_ATTRIB); 109 | glEnableVertexAttribArray(COLOR_ATTRIB); 110 | 111 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_SCALEROT]); 112 | glVertexAttribPointer(SCALEROT_ATTRIB, 4, GL_FLOAT, GL_FALSE, 4*sizeof(float), 0); 113 | glEnableVertexAttribArray(SCALEROT_ATTRIB); 114 | glVertexAttribDivisor(SCALEROT_ATTRIB, 1); 115 | 116 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_OFFSET]); 117 | glVertexAttribPointer(OFFSET_ATTRIB, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), 0); 118 | glEnableVertexAttribArray(OFFSET_ATTRIB); 119 | glVertexAttribDivisor(OFFSET_ATTRIB, 1); 120 | 121 | ALOGV("Using OpenGL ES 3.0 renderer"); 122 | return true; 123 | } 124 | 125 | RendererES3::~RendererES3() { 126 | /* The destructor may be called after the context has already been 127 | * destroyed, in which case our objects have already been destroyed. 128 | * 129 | * If the context exists, it must be current. This only happens when we're 130 | * cleaning up after a failed init(). 131 | */ 132 | if (eglGetCurrentContext() != mEglContext) 133 | return; 134 | glDeleteVertexArrays(1, &mVBState); 135 | glDeleteBuffers(VB_COUNT, mVB); 136 | glDeleteProgram(mProgram); 137 | } 138 | 139 | float* RendererES3::mapOffsetBuf() { 140 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_OFFSET]); 141 | return (float*)glMapBufferRange(GL_ARRAY_BUFFER, 142 | 0, MAX_INSTANCES * 2*sizeof(float), 143 | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); 144 | } 145 | 146 | void RendererES3::unmapOffsetBuf() { 147 | glUnmapBuffer(GL_ARRAY_BUFFER); 148 | } 149 | 150 | float* RendererES3::mapTransformBuf() { 151 | glBindBuffer(GL_ARRAY_BUFFER, mVB[VB_SCALEROT]); 152 | return (float*)glMapBufferRange(GL_ARRAY_BUFFER, 153 | 0, MAX_INSTANCES * 4*sizeof(float), 154 | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); 155 | } 156 | 157 | void RendererES3::unmapTransformBuf() { 158 | glUnmapBuffer(GL_ARRAY_BUFFER); 159 | } 160 | 161 | void RendererES3::draw(unsigned int numInstances) { 162 | glUseProgram(mProgram); 163 | glBindVertexArray(mVBState); 164 | glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, numInstances); 165 | } 166 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/cpp/gles3jni.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef GLES3JNI_H 18 | #define GLES3JNI_H 1 19 | 20 | #include 21 | #include 22 | 23 | #if DYNAMIC_ES3 24 | #include "gl3stub.h" 25 | #else 26 | // Include the latest possible header file( GL version header ) 27 | #if __ANDROID_API__ >= 24 28 | #include 29 | #elif __ANDROID_API__ >= 21 30 | #include 31 | #else 32 | #include 33 | #endif 34 | 35 | #endif 36 | 37 | #define DEBUG 1 38 | 39 | #define LOG_TAG "GLES3JNI" 40 | #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 41 | #if DEBUG 42 | #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) 43 | #else 44 | #define ALOGV(...) 45 | #endif 46 | 47 | // ---------------------------------------------------------------------------- 48 | // Types, functions, and data used by both ES2 and ES3 renderers. 49 | // Defined in gles3jni.cpp. 50 | 51 | #define MAX_INSTANCES_PER_SIDE 16 52 | #define MAX_INSTANCES (MAX_INSTANCES_PER_SIDE * MAX_INSTANCES_PER_SIDE) 53 | #define TWO_PI (2.0 * M_PI) 54 | #define MAX_ROT_SPEED (0.3 * TWO_PI) 55 | 56 | // This demo uses three coordinate spaces: 57 | // - The model (a quad) is in a [-1 .. 1]^2 space 58 | // - Scene space is either 59 | // landscape: [-1 .. 1] x [-1/(2*w/h) .. 1/(2*w/h)] 60 | // portrait: [-1/(2*h/w) .. 1/(2*h/w)] x [-1 .. 1] 61 | // - Clip space in OpenGL is [-1 .. 1]^2 62 | // 63 | // Conceptually, the quads are rotated in model space, then scaled (uniformly) 64 | // and translated to place them in scene space. Scene space is then 65 | // non-uniformly scaled to clip space. In practice the transforms are combined 66 | // so vertices go directly from model to clip space. 67 | 68 | struct Vertex { 69 | GLfloat pos[2]; 70 | GLubyte rgba[4]; 71 | }; 72 | extern const Vertex QUAD[4]; 73 | 74 | // returns true if a GL error occurred 75 | extern bool checkGlError(const char* funcName); 76 | extern GLuint createShader(GLenum shaderType, const char* src); 77 | extern GLuint createProgram(const char* vtxSrc, const char* fragSrc); 78 | 79 | // ---------------------------------------------------------------------------- 80 | // Interface to the ES2 and ES3 renderers, used by JNI code. 81 | 82 | class Renderer { 83 | public: 84 | virtual ~Renderer(); 85 | void resize(int w, int h); 86 | void render(); 87 | 88 | protected: 89 | Renderer(); 90 | 91 | // return a pointer to a buffer of MAX_INSTANCES * sizeof(vec2). 92 | // the buffer is filled with per-instance offsets, then unmapped. 93 | virtual float* mapOffsetBuf() = 0; 94 | virtual void unmapOffsetBuf() = 0; 95 | // return a pointer to a buffer of MAX_INSTANCES * sizeof(vec4). 96 | // the buffer is filled with per-instance scale and rotation transforms. 97 | virtual float* mapTransformBuf() = 0; 98 | virtual void unmapTransformBuf() = 0; 99 | 100 | virtual void draw(unsigned int numInstances) = 0; 101 | 102 | private: 103 | void calcSceneParams(unsigned int w, unsigned int h, float* offsets); 104 | void step(); 105 | 106 | unsigned int mNumInstances; 107 | float mScale[2]; 108 | float mAngularVelocity[MAX_INSTANCES]; 109 | uint64_t mLastFrameNs; 110 | float mAngles[MAX_INSTANCES]; 111 | }; 112 | 113 | extern Renderer* createES2Renderer(); 114 | extern Renderer* createES3Renderer(); 115 | 116 | #endif // GLES3JNI_H 117 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/java/com/android/gles3/GLES3JNIActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.gles3; 18 | 19 | import android.app.Activity; 20 | import android.os.Bundle; 21 | import android.util.Log; 22 | import android.view.WindowManager; 23 | 24 | import java.io.File; 25 | 26 | public class GLES3JNIActivity extends Activity { 27 | 28 | GLES3JNIView mView; 29 | 30 | @Override protected void onCreate(Bundle icicle) { 31 | super.onCreate(icicle); 32 | mView = new GLES3JNIView(getApplication()); 33 | setContentView(mView); 34 | } 35 | 36 | @Override protected void onPause() { 37 | super.onPause(); 38 | mView.onPause(); 39 | } 40 | 41 | @Override protected void onResume() { 42 | super.onResume(); 43 | mView.onResume(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/java/com/android/gles3/GLES3JNILib.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.gles3; 18 | 19 | // Wrapper for native library 20 | 21 | public class GLES3JNILib { 22 | 23 | static { 24 | System.loadLibrary("gles3"); 25 | } 26 | 27 | public static native void init(); 28 | public static native void resize(int width, int height); 29 | public static native void step(); 30 | } 31 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/java/com/android/gles3/GLES3JNIView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.android.gles3; 18 | 19 | import android.content.Context; 20 | import android.graphics.PixelFormat; 21 | import android.opengl.GLSurfaceView; 22 | import android.util.AttributeSet; 23 | import android.util.Log; 24 | import android.view.KeyEvent; 25 | import android.view.MotionEvent; 26 | 27 | import javax.microedition.khronos.egl.EGL10; 28 | import javax.microedition.khronos.egl.EGLConfig; 29 | import javax.microedition.khronos.egl.EGLContext; 30 | import javax.microedition.khronos.egl.EGLDisplay; 31 | import javax.microedition.khronos.opengles.GL10; 32 | 33 | class GLES3JNIView extends GLSurfaceView { 34 | private static final String TAG = "GLES3JNI"; 35 | private static final boolean DEBUG = true; 36 | 37 | public GLES3JNIView(Context context) { 38 | super(context); 39 | // Pick an EGLConfig with RGB8 color, 16-bit depth, no stencil, 40 | // supporting OpenGL ES 2.0 or later backwards-compatible versions. 41 | setEGLConfigChooser(8, 8, 8, 0, 16, 0); 42 | setEGLContextClientVersion(3); 43 | setRenderer(new Renderer()); 44 | } 45 | 46 | private static class Renderer implements GLSurfaceView.Renderer { 47 | public void onDrawFrame(GL10 gl) { 48 | GLES3JNILib.step(); 49 | } 50 | 51 | public void onSurfaceChanged(GL10 gl, int width, int height) { 52 | GLES3JNILib.resize(width, height); 53 | } 54 | 55 | public void onSurfaceCreated(GL10 gl, EGLConfig config) { 56 | GLES3JNILib.init(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL3/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL3/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL3/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /build-app/GL3/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 19 | 20 | 21 | 22 | GLES3 23 | 24 | 25 | -------------------------------------------------------------------------------- /build-app/GL3/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:8.6.0' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build-app/GL3/gles3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/GL3/gles3.jpg -------------------------------------------------------------------------------- /build-app/GL3/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /build-app/GL3/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /build-app/GL3/local.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | 7 | # location of the SDK. This is only used by Ant 8 | # For customization when using a Version Control System, please read the 9 | # header note 10 | 11 | # android-sdk location 12 | sdk.dir=/data/data/com.termux/files/home/opt/android-sdk 13 | 14 | # android-ndk location 15 | ndk.dir=/data/data/com.termux/files/home/opt/android-ndk-r27b 16 | 17 | # cmake location 18 | cmake.dir=/data/data/com.termux/files/home/opt/android-sdk/cmake 19 | -------------------------------------------------------------------------------- /build-app/GL3/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /build-app/README.md: -------------------------------------------------------------------------------- 1 | ### How to use termux-ndk to build android app 2 | 3 | Download the `android-ndk` and `android-sdk` from [release](https://github.com/Lzhiyong/termux-ndk/releases) 4 | ```bash 5 | # install openjdk-17 6 | pkg install openjdk-17 7 | 8 | # install gradle 9 | pkg install gradle 10 | 11 | ``` 12 | 13 | Add a `local.properties` file to the root of the project as below 14 | ```local.properties 15 | # modify the local.properties file 16 | # although ndk.dir has been deprecated, but it still works 17 | sdk.dir=/path/to/android-sdk 18 | ndk.dir=/path/to/android-ndk 19 | cmake.dir=/path/to/cmake 20 | # for example: 21 | sdk.dir=/data/data/com.termux/files/home/opt/android-sdk 22 | ndk.dir=/data/data/com.termux/files/home/opt/android-ndk-r27b 23 | cmake.dir=/data/data/com.termux/files/home/opt/android-sdk/cmake 24 | ``` 25 | Modify the `project/build.gradle.kts` file 26 | ```build.gradle.kts 27 | // set the Android gradle plugin version 28 | plugins { 29 | id("com.android.application") version "8.6.0" apply false 30 | id("com.android.library") version "8.6.0" apply false 31 | id("org.jetbrains.kotlin.android") version "2.0.20" apply false 32 | } 33 | ``` 34 | Modify the project `app/build.gradle.kts` file 35 | ```build.gradle.kts 36 | 37 | android { 38 | // set the build tools version 39 | buildToolsVersion = "35.0.0" 40 | 41 | externalNativeBuild { 42 | cmake { 43 | path("src/main/cpp/CMakeLists.txt") 44 | // If your cmake version >= 3.21, you must specify a version 45 | // 3.18.5+ or 3.25.1 and so on 46 | version = "3.25.1" 47 | } 48 | } 49 | } 50 | ``` 51 | 52 | Execute the `gradle build` command to start building the android app, when building for the first time, 53 | the exec format error will occur, because the aapt2 is x86_64 architecture not aarch64, so we need to replace it 54 | 55 | ```bash 56 | # replace the aapt2 with your own 57 | # note: it's /path/to not /path/to/aapt2 58 | find ~/.gradle -name 'aapt2-*-linux.jar' -type f | xargs -I{} jar -uvf {} -C /path/to aapt2 59 | ``` 60 | If an error occurs during the build app, this may be a network problem, please execute the `gradle build` again or execute the `gradle build --info` for more information. 61 | 62 | **** 63 | 64 | ### Building termux-app with termux 65 | ```gradle.properties 66 | # clone the termux-app 67 | git clone --depth=1 https://github.com/termux/termux-app 68 | 69 | # add a local.properties file 70 | sdk.dir=/path/to/android-sdk 71 | ndk.dir=/path/to/android-ndk 72 | cmake.dir=/path/to/cmake 73 | 74 | # modify gradle.properties file 75 | minSdkVersion=24 76 | targetSdkVersion=28 77 | ndkVersion=27.1.12297006 78 | compileSdkVersion=35 79 | buildToolsVersion=35.0.0 80 | 81 | # modify the build.gradle file 82 | # termux-app/app/build.gradle 83 | # terminal-emulator/build.gradle 84 | # terminal-view/build.gradle 85 | # termux-shared/build.gradle 86 | # set the buildToolsVersion 87 | android { 88 | ... 89 | compileSdkVersion project.properties.compileSdkVersion.toInteger() 90 | // set the build tools version 91 | buildToolsVersion project.properties.buildToolsVersion.toString() 92 | ... 93 | } 94 | 95 | # start building 96 | gradle assembleDebug 97 | 98 | ``` 99 |
100 | 101 |
102 | 103 | **** 104 | ### Building example 105 | ```bash 106 | # GL2 107 | cd GL2 && gradle installDebug 108 | 109 | # GL3 110 | cd GL3 && gradle installDebug 111 | 112 | ``` 113 |
114 | 115 |
116 | 117 | **** 118 | 119 | ### Known issues 120 | Using proot or chroot linux is not recommended, this may have some problems, the building speed is much slower than the native Termux. 121 | -------------------------------------------------------------------------------- /build-app/rust-example/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | /bin/ 15 | /gen/ 16 | /out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # Gradle files 19 | .gradle/ 20 | /build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | #local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # IntelliJ 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/assetWizardSettings.xml 43 | .idea/dictionaries 44 | .idea/libraries 45 | # Android Studio 3 in .gitignore file. 46 | .idea/caches 47 | .idea/modules.xml 48 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 49 | .idea/navEditor.xml 50 | 51 | # Keystore files 52 | # Uncomment the following lines if you do not want to check your keystore files in. 53 | #*.jks 54 | #*.keystore 55 | 56 | # External native build folder generated in Android Studio 2.2 and later 57 | .externalNativeBuild 58 | .cxx/ 59 | 60 | # Google Services (e.g. APIs or Firebase) 61 | # google-services.json 62 | 63 | # Freeline 64 | freeline.py 65 | freeline/ 66 | freeline_project_description.json 67 | 68 | # fastlane 69 | fastlane/report.xml 70 | fastlane/Preview.html 71 | fastlane/screenshots 72 | fastlane/test_output 73 | fastlane/readme.md 74 | 75 | # Version control 76 | vcs.xml 77 | 78 | # lint 79 | lint/intermediates/ 80 | lint/generated/ 81 | lint/outputs/ 82 | lint/tmp/ 83 | # lint/reports/ 84 | -------------------------------------------------------------------------------- /build-app/rust-example/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /build-app/rust-example/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | id("org.mozilla.rust-android-gradle.rust-android") 5 | } 6 | 7 | android { 8 | namespace = "com.rust.example" 9 | buildToolsVersion = "35.0.0" 10 | compileSdk = 33 11 | 12 | defaultConfig { 13 | applicationId = "com.rust.example" 14 | minSdk = 21 15 | targetSdk = 33 16 | versionCode = 1 17 | versionName = "1.0" 18 | 19 | vectorDrawables { 20 | useSupportLibrary = true 21 | } 22 | } 23 | 24 | compileOptions { 25 | sourceCompatibility = JavaVersion.VERSION_17 26 | targetCompatibility = JavaVersion.VERSION_17 27 | } 28 | 29 | buildTypes { 30 | release { 31 | isMinifyEnabled = true 32 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 33 | } 34 | } 35 | 36 | buildFeatures { 37 | viewBinding = true 38 | } 39 | 40 | cargo { 41 | prebuiltToolchains = true 42 | module = "../rust" // Or whatever directory contains your Cargo.toml 43 | libname = "rust" // Or whatever matches Cargo.toml's [package] name. 44 | targets = listOf("arm64", "arm", "x86", "x86_64") // See bellow for a longer list of options 45 | } 46 | 47 | tasks.whenTaskAdded { 48 | if((name == "javaPreCompileDebug" || name == "javaPreCompileRelease")) { 49 | dependsOn("cargoBuild") 50 | } 51 | } 52 | 53 | } 54 | 55 | tasks.withType().configureEach { 56 | kotlinOptions.jvmTarget = "17" 57 | } 58 | 59 | dependencies { 60 | implementation("androidx.constraintlayout:constraintlayout:2.1.4") 61 | implementation("com.google.android.material:material:1.9.0") 62 | implementation("androidx.appcompat:appcompat:1.6.1") 63 | } 64 | -------------------------------------------------------------------------------- /build-app/rust-example/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 12 | 15 | 16 | 18 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/kotlin/com/rust/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.rust.example 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.util.Log 6 | import com.rust.example.databinding.ActivityMainBinding 7 | 8 | public class MainActivity : AppCompatActivity() { 9 | 10 | private var _binding: ActivityMainBinding? = null 11 | 12 | private val binding: ActivityMainBinding 13 | get() = checkNotNull(_binding) { "Activity has been destroyed" } 14 | 15 | private val TAG = this::class.simpleName 16 | 17 | companion object { 18 | init { 19 | // load the libnative.so from rust 20 | System.loadLibrary("rust") 21 | } 22 | 23 | // JNI fun 24 | external fun stringFromRust(): String 25 | 26 | } 27 | 28 | override fun onCreate(savedInstanceState: Bundle?) { 29 | super.onCreate(savedInstanceState) 30 | 31 | // Inflate and get instance of binding 32 | _binding = ActivityMainBinding.inflate(layoutInflater) 33 | 34 | // set content view to binding's root 35 | setContentView(binding.root) 36 | 37 | binding.textView.setText(stringFromRust()) 38 | 39 | Log.i(TAG, "rust-jni-example") 40 | } 41 | 42 | override fun onDestroy() { 43 | super.onDestroy() 44 | _binding = null 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/rust-example/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/values-night/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /build-app/rust-example/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 7 | 8 |