├── .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 | 
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 | 
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 |
9 |
--------------------------------------------------------------------------------
/build-app/rust-example/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/build-app/rust-example/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | rust-exampe
4 |
5 |
--------------------------------------------------------------------------------
/build-app/rust-example/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/build-app/rust-example/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/build-app/rust-example/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/build-app/rust-example/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id("com.android.application") version "8.6.0" apply false
4 | id("com.android.library") version "8.6.0" apply false
5 | id("org.jetbrains.kotlin.android") version "2.0.20" apply false
6 | id("org.mozilla.rust-android-gradle.rust-android") version "0.9.3" apply false
7 | }
8 |
9 | tasks.register("clean") {
10 | delete(rootProject.buildDir)
11 | }
--------------------------------------------------------------------------------
/build-app/rust-example/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx512m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/build-app/rust-example/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 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/build-app/rust-example/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/rust-example/rust/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | Cargo.lock
3 |
--------------------------------------------------------------------------------
/build-app/rust-example/rust/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rust"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | jni = "0.21.1"
10 |
11 | [lib]
12 | name = "rust"
13 | crate_type = ["staticlib", "dylib"]
14 |
15 |
--------------------------------------------------------------------------------
/build-app/rust-example/rust/src/lib.rs:
--------------------------------------------------------------------------------
1 | // This is the interface to the JVM that we'll
2 | // call the majority of our methods on.
3 | use jni::JNIEnv;
4 |
5 | // These objects are what you should use as arguments to your native function.
6 | // They carry extra lifetime information to prevent them escaping from the
7 | // current local frame (which is the scope within which local (temporary)
8 | // references to Java objects remain valid)
9 | use jni::objects::{JClass, JString};
10 |
11 | // This `#[no_mangle]` keeps rust from "mangling" the name and making it unique
12 | // for this crate. The name follow a strict naming convention so that the
13 | // JNI implementation will be able to automatically find the implementation
14 | // of a native method based on its name.
15 | //
16 | // The `'local` lifetime here represents the local frame within which any local
17 | // (temporary) references to Java objects will remain valid.
18 | //
19 | // It's usually not necessary to explicitly name the `'local` input lifetimes but
20 | // in this case we want to return a reference and show the compiler what
21 | // local frame lifetime it is associated with.
22 | //
23 | // Alternatively we could instead return the `jni::sys::jstring` type instead
24 | // which would represent the same thing as a raw pointer, without any lifetime,
25 | // and at the end use `.into_raw()` to convert a local reference with a lifetime
26 | // into a raw pointer.
27 | #[no_mangle]
28 | pub extern "system" fn Java_com_rust_example_MainActivity_00024Companion_stringFromRust<'local>(
29 | // Notice that this `env` argument is mutable. Any `JNIEnv` API that may
30 | // allocate new object references will take a mutable reference to the
31 | // environment.
32 | env: JNIEnv<'local>,
33 | // this is the class that owns our static method. Not going to be used, but
34 | // still needs to have an argument slot
35 | _class: JClass<'local>
36 | ) -> JString<'local> {
37 | // we have to create a new java string to return. Again, more info
38 | // in the `strings` module.
39 | env.new_string("Hello Rust!!🦀")
40 | .expect("Couldn't create java string!")
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/build-app/rust-example/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 |
9 | dependencyResolutionManagement {
10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11 | repositories {
12 | google()
13 | mavenCentral()
14 | }
15 | }
16 |
17 | rootProject.name = "rust-exampe"
18 |
19 | include(":app")
--------------------------------------------------------------------------------
/build-app/screenshot/build_termux_app1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/screenshot/build_termux_app1.jpg
--------------------------------------------------------------------------------
/build-app/screenshot/build_termux_app2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lzhiyong/termux-ndk/6a567aa4ee9455b7b57e9b9f135dbf63d22141c3/build-app/screenshot/build_termux_app2.jpg
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | /out
2 |
--------------------------------------------------------------------------------
/docs/Architecture.md:
--------------------------------------------------------------------------------
1 | # Architecture
2 |
3 | The latest version of this document is available at
4 | https://android.googlesource.com/platform/ndk/+/master/docs/Architecture.md.
5 |
6 | The core NDK is the zip file that is built in this repository and distributed by
7 | the SDK manager. It bundles the outputs of several other projects into a package
8 | that is directly usable by app developers, and also includes a few projects
9 | maintained directly in this repository.
10 |
11 | More broadly, "the NDK" can refer to the C ABI exposed to apps by the OS (AKA
12 | "the platform").
13 |
14 | ## Code map
15 |
16 | The code in the NDK repo (the "repo" repository, the meta-repo that was created
17 | with `repo init` and `repo sync`, the parent directory of this git repo) is
18 | organized as follows:
19 |
20 | ### bionic
21 |
22 | The source for bionic, Android's libc (and friends). The sources and includes
23 | for building the CRT objects come from this repository.
24 |
25 | ### development
26 |
27 | The repository itself is overly broad. We include it for the adb python package.
28 |
29 | ### external
30 |
31 | Most third-party code lives in external. For example, this is where googletest
32 | and some of the vulkan code lives.
33 |
34 | ### ndk
35 |
36 | The main NDK repository. This is where the build systems and the NDK's own build
37 | and test systems live. This directory is organized as:
38 |
39 | #### Main directory
40 |
41 | The main directory contains the entry points to the build (`checkbuild.py`) and
42 | test (`run_tests.py`) scripts, as well as Python configuration files like
43 | mypy.ini and pylintrc. The other loose files in this directory such as ndk-gdb
44 | are the sources for tools that are shipped in the NDK that should probably be
45 | moved into their own directory for clarity.
46 |
47 | #### bootstrap
48 |
49 | Python 2/3 library for bootstrapping our build and test tools with an up to date
50 | Python 3.
51 |
52 | #### build
53 |
54 | Contains the build systems shipped in the NDK:
55 |
56 | * CMake toolchain files
57 | * ndk-build
58 | * `make_standalone_toolchain.py`
59 |
60 | #### docs
61 |
62 | Documentation primarily for core NDK development. Some additional documentation
63 | lives here as well but most user documentation lives in google3.
64 |
65 | #### infra
66 |
67 | Some infrastructure scripts like a Dockerfile that can be used to build the NDK.
68 |
69 | #### meta
70 |
71 | Metadata for the NDK intended for consumption by external tools and build
72 | systems to avoid needing to hard code or infer properties like the minimum and
73 | maximum OS versions or ABIs supported.
74 |
75 | #### ndk
76 |
77 | The Python package used for building and testing the NDK. The top level
78 | `checkbuild.py` and `run_tests.py` scripts call into this package.
79 |
80 | #### samples
81 |
82 | Sample projects to use for non-automated testing.
83 |
84 | #### scripts
85 |
86 | Additional scripts used for NDK development and release processes. Some of these
87 | scripts may be unfinished or unused, but the development and release
88 | documentation will guide you to the correct ones.
89 |
90 | #### sources
91 |
92 | Sources for tools and libraries shipped in the NDK that are not maintained in a
93 | separate repository.
94 |
95 | #### tests
96 |
97 | The NDK's tests. See [Testing.md](Testing.md) for more information.
98 |
99 | #### wrap.sh
100 |
101 | Premade [wrap.sh](https://developer.android.com/ndk/guides/wrap-script) scripts
102 | for apps.
103 |
104 | ### prebuilts
105 |
106 | Prebuilt toolchains and libraries used or shipped (or both) by the NDK. The LLVM
107 | toolchain we ship is in prebuilts/clang, and the sysroot is in prebuilts/ndk.
108 |
109 | ### toolchain
110 |
111 | Sources for the toolchain and other build components. LLVM lives in
112 | toolchain/llvm-project.
113 |
114 | ## Core NDK
115 |
116 | The NDK components can be loosely grouped into the toolchain (the compiler as
117 | well as its supporting tools and libraries), build systems, and support
118 | libraries.
119 |
120 | For more information, see the [Build System Maintainers] guide.
121 |
122 | [Build System Maintainers]: docs/BuildSystemMaintainers.md
123 |
124 | ### Toolchain
125 |
126 | The NDK's toolchain is LLVM. This means the NDK uses Clang as its compiler and
127 | the rest of the LLVM suite for other tasks (LLD for linking, llvm-ar for static
128 | library creation, etc).
129 |
130 | The toolchain is delivered to the NDK in a prebuilt form via the prebuilts/clang
131 | repositories. The version of the toolchain to be used is defined (at the time of
132 | writing) by `ndk.toolchains.CLANG_VERSION`.
133 |
134 | Documentation for using the NDK toolchain can be found in the [Build System
135 | Maintainers] guide. Information on how to update and test the prebuilt toolchain
136 | in the NDK can be found in the [Toolchains](Toolchains.md) guide.
137 |
138 | ### Build systems
139 |
140 | While the NDK is primarily a toolchain for building Android code, the package
141 | also includes some build system support.
142 |
143 | First, `$NDK/build/core` contains ndk-build. This is the NDK's home grown build
144 | system. The entry point for this build system is `$NDK/build/ndk-build` (or
145 | `$NDK/build/ndk-build.cmd`).
146 |
147 | A CMake toolchain file is included at
148 | `$NDK/build/cmake/android.toolchain.cmake`. This toolchain file configures some
149 | default behaviors and then delegates to the [built-in CMake NDK support], which
150 | in turn allows the NDK to customize some internal behaviors via the hooks in
151 | `$NDK/build/cmake/hooks`. For some configurations, CMake support for the NDK is
152 | entirely implemented in `android-legacy.toolchain.cmake`. Which toolchain is
153 | used by default depends on both the NDK and CMake version, as we will default to
154 | the legacy toolchain file when the new toolchain file has known regressions. To
155 | determine which behavior is the default for a given NDK, check the fallback
156 | condition in `android.toolchain.cmake`.
157 |
158 | [built-in CMake NDK support]: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android
159 |
160 | `$NDK/build/tools/make_standalone_toolchain.py` is a tool which can create a
161 | redistributable toolchain that targets a single Android ABI and API level. As of
162 | NDK r19 it is unnecessary, as the installed toolchain may be invoked directly,
163 | but it remains for compatibility.
164 |
165 | Apps and Android libraries (AARs) are typically built by the Gradle using the
166 | Android Gradle Plugin (AGP). AGP uses `externalNativeBuild` tasks to delegate
167 | the native build to either CMake or ndk-build and then handles packaging the
168 | built libraries into the APK. Since the Android Gradle plugin is responsible for
169 | both Java and native code, is not included as part of the NDK.
170 |
171 | ### Support libraries
172 |
173 | `sources/android` and `sources/third_party` contain modules that can be used in
174 | apps (gtest, cpufeatures, native\_app\_glue, etc) via `$(call
175 | import-module,$MODULE)` in ndk-build. CMake modules are not yet available.
176 |
177 | ## The platform
178 |
179 | Most of what NDK users mean when they refer to "the NDK" is actually the C API
180 | surface that is exposed by the OS. These are present in what we consider the NDK
181 | (the zip file we ship) as header files and stub libraries in the sysroot.
182 |
183 | Each NDK contains a single set of headers for describing all the API levels it
184 | supports. This means that the same headers are used whether the user's
185 | `minSdkVersion` is 19 or 30, so APIs are annotated with
186 | `__attribute__((available))` so that the compiler can diagnose use of
187 | unavailable APIs.
188 |
189 | Stub libraries are provided per supported API level. The stub libraries matching
190 | the user's `minSdkVersion` are used at build time to ensure that apps only use
191 | symbols which are available (though in the future these may be [weak
192 | references](https://github.com/android/ndk/issues/837) to allow apps a more
193 | ergonomic method of conditionally accessing maybe-available APIs). The stub
194 | libraries are **not** packaged in the APK, but instead are loaded from the OS.
195 |
196 | Sysroot updates (new system APIs) are delivered to the NDK when an update is
197 | manually triggered. The platform build generates the sysroot, and that artifact
198 | is snapshot in prebuilts/ndk/platform. The prebuilt that is checked in is what
199 | will be shipped.
200 |
--------------------------------------------------------------------------------
/docs/Building.md:
--------------------------------------------------------------------------------
1 | # Building the NDK
2 |
3 | The latest version of this document is available at
4 | https://android.googlesource.com/platform/ndk/+/master/docs/Building.md.
5 |
6 | Both Linux and Windows NDKs are built on Linux machines. Windows host binaries
7 | are cross-compiled with MinGW.
8 |
9 | Building the NDK for Mac OS X requires at least 10.13.
10 |
11 | ## Prerequisites
12 |
13 | The first thing you need is the AOSP NDK repository. If you're new to using repo
14 | and gerrit, see [repo.md](repo.md) for tips. If you're already familiar with how
15 | to use repo and gerrit from other Android projects, you already know plenty :)
16 |
17 | Check out the branch `master-ndk`. Do this in a new directory.
18 |
19 | ```bash
20 | # For non-Googlers:
21 | repo init -u https://android.googlesource.com/platform/manifest -b master-ndk --partial-clone
22 |
23 | # Googlers, follow http://go/repo-init/master-ndk (select AOSP in the Host menu,
24 | # and uncheck the box for the git superproject). At time of writing, the correct
25 | # invocation is:
26 | repo init -u \
27 | sso://android.git.corp.google.com/platform/manifest -b master-ndk --partial-clone
28 | ```
29 |
30 | If you wish to rebuild a given release of the NDK, the release branches can also
31 | be checked out. They're named `ndk-release-r${RELEASE}` for newer releases, but
32 | `ndk-r{RELEASE}-release` for older releases. For example, to check out the r19
33 | release branch, use the `-b ndk-release-r19` flag instad of `-b master-ndk`.
34 |
35 | Linux dependencies are listed in the [Dockerfile]. You can use docker to build
36 | the NDK:
37 |
38 | ```bash
39 | docker build -t ndk-dev infra/docker
40 | docker run -it -u $UID -v `realpath ..`:/src -w /src/ndk ndk-dev ./checkbuild.py
41 | ```
42 |
43 | Building on Mac OS X has similar dependencies as Linux, but also requires Xcode.
44 |
45 | Running tests requires that `adb` is in your `PATH`. This is provided as part of
46 | the [Android SDK].
47 |
48 | [Dockerfile]: ../infra/docker/Dockerfile
49 | [Android SDK]: https://developer.android.com/studio/index.html#downloads
50 |
51 | ## Python environment setup
52 |
53 | To set up your environment to use the correct versions of Python and Python
54 | packages, install [Poetry](https://python-poetry.org/) and then do the
55 | following.
56 |
57 | Whenever you set up a new NDK tree (after a fresh `repo init`, for example),
58 | configure the project to use our prebuilt Python instead of your system's. If on
59 | Mac, be sure to use the darwin-x86 version instead.
60 |
61 | ```bash
62 | poetry env use ../prebuilts/python/linux-x86/bin/python3
63 | ```
64 |
65 | The first time, and also anytime you sync because there might be new or updated
66 | dependencies, install the NDK dependencies to the virtualenv managed by poetry.
67 |
68 | ```bash
69 | poetry install
70 | ```
71 |
72 | Note: If `poetry install` hangs on Linux, try
73 | `PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring poetry install`.
74 |
75 | Spawn a new shell using the virtualenv that Poetry created. You could instead
76 | run NDK commands with the `poetry run` prefix (e.g. `poetry run
77 | ./checkbuild.py`), but it's simpler to just spawn a new shell. Plus, if it's in
78 | your environment your editor can use it.
79 |
80 | ```bash
81 | poetry shell
82 | ```
83 |
84 | ### macOS workarounds
85 |
86 | On macOS you may not be able to use the Python that is in prebuilts because it
87 | does not support the ssl module (which poetry itself needs). Until the Python
88 | prebuilt includes that module, do the following to use a different Python:
89 |
90 | First time setup: ensure that you have pyenv installed. You may need to install
91 | homebrew (http://go/homebrew for Googlers, else https://brew.sh/).
92 |
93 | ```
94 | $ brew update && brew upgrade pyenv
95 | ```
96 |
97 | Then set up your tree to use the correct version of Python. This setting will
98 | apply to the directory it is run in, so you will need to do it per NDK tree.
99 |
100 | ```
101 | # From the //ndk directory of your NDK tree:
102 | $ ../prebuilts/python/darwin-x86/bin/python3 --version
103 | Python 3.11.4
104 | # We don't need to match the version exactly, just the major/minor version.
105 | $ pyenv install 3.11:latest
106 | $ pyenv local 3.11
107 | $ python --version
108 | Python 3.11.8
109 | $ poetry env use 3.11
110 | poetry install
111 | ```
112 |
113 | Each time the NDK updates to a new version of Python, you'll need to repeat
114 | those steps. You may also need to remove the old poetry environment
115 | (`poetry env list` to get the name, `poetry env remove` to remove it).
116 |
117 | `checkbuild.py` and `run_tests.py` will complain when you try to use a Python
118 | that doesn't come from prebuilts by default. To suppress that, pass
119 | `--permissive-python-environment` when using those tools in this environment.
120 |
121 | ## Build
122 |
123 | ### For Linux or Darwin
124 |
125 | ```bash
126 | $ python checkbuild.py
127 | ```
128 |
129 | If you get an error like the following:
130 |
131 | ```
132 | Expected python to be $NDK_SRC/prebuilts/python/$HOST/bin/python3.9, but is ~/.cache/pypoetry/virtualenvs/$VENV/bin/python (/usr/bin/python3.9).
133 | ```
134 |
135 | Your Poetry virualenv was misconfigured. It seems that `poetry env use` will not
136 | replace an existing virtualenv of the same major/minor version, so if you ran
137 | any poetry commands before `poetry env use`, your environment needs to be
138 | deleted and recreated.
139 |
140 | ```bash
141 | $ poetry env remove $VENV
142 | $ poetry env use ../prebuilts/python/linux-x86/bin/python3
143 | $ poetry install
144 | ```
145 |
146 | If you get an error like the following:
147 |
148 | ```
149 | Expected python to be $NDK_SRC/prebuilts/python/linux-x86/bin/python3.9, but is /usr/bin/python (/usr/bin/python3.9).
150 | ```
151 |
152 | You ran checkbuild.py outside the poetry environment. Ensure that you've done
153 | the first time setup (`poetry env use` and `poetry install`, as above), then
154 | either run `poetry shell` to enter a new shell with the correct environment, or
155 | use `poetry run checkbuild.py`.
156 |
157 | If you get errors from the pythonlint task but it appears to only affect your
158 | machine, one of the linters you have installed is probably not the correct
159 | version. Run `poetry install` to sync your environment with the expected
160 | versions.
161 |
162 | ### For Windows, from Linux
163 |
164 | ```bash
165 | $ python checkbuild.py --system windows64
166 | ```
167 |
168 | `checkbuild.py` will also build all of the NDK tests. This takes about 3x as
169 | long as building the NDK itself, so pass `--no-build-tests` to skip building the
170 | tests if you're iterating on build behavior or plan to rebuild only specific
171 | tests. Tests can be built later with `python run_tests.py --rebuild`.
172 |
173 | Note: The NDK's build and test scripts are implemented in Python 3 (currently
174 | 3.9). `checkbuild.py` will use a prebuilt Python, but `run_tests.py` does not do
175 | this yet. `run_tests.py` also can be run outside of a complete development
176 | environment (as it is when it is run on Windows), so a Python 3.9 virtualenv is
177 | recommended.
178 |
179 | ## Packaging
180 |
181 | Packaging uses `zip -9` so is extremely time consuming and disabled by default.
182 | Use the `--package` flag to force packaging locally. This is not required for
183 | local development and only needs to be used when testing packaging behavior.
184 |
--------------------------------------------------------------------------------
/docs/ClangMigration.md:
--------------------------------------------------------------------------------
1 | # Clang Migration Notes
2 |
3 | NDK r17 was the last version to include GCC. If you're upgrading from an old NDK
4 | and need to migrate to Clang, this doc can help.
5 |
6 | If you maintain a custom build system, see the [Build System Maintainers]
7 | documentation.
8 |
9 | [Build System Maintainers]: ./BuildSystemMaintainers.md
10 |
11 | ## `-Oz` versus `-Os`
12 |
13 | [Clang Optimization Flags](https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options)
14 | has the full details, but if you used `-Os` to optimize your
15 | code for size with GCC, you probably want `-Oz` when using
16 | Clang. Although `-Os` attempts to make code small, it still
17 | enables some optimizations that will increase code size (based on
18 | https://stackoverflow.com/a/15548189/632035). For the smallest possible
19 | code with Clang, prefer `-Oz`. With `-Oz`, Chromium actually saw both
20 | size *and* performance improvements when moving to Clang compared to
21 | `-Os` with GCC.
22 |
23 | ## `__attribute__((__aligned__))`
24 |
25 | Normally the `__aligned__` attribute is given an explicit alignment,
26 | but with no value means “maximum alignment”. The interpretation of
27 | “maximum” differs between GCC and Clang: Clang includes vector types
28 | too so for ARM GCC thinks the maximum alignment is 8 (for `uint64_t`), but
29 | Clang thinks it’s 16 (because there are NEON instructions that require
30 | 16-byte alignment). Normally this shouldn’t matter because malloc is
31 | always at least 16-byte aligned, and mmap regions are page (4096-byte)
32 | aligned. Most code should either specify an explicit alignment or use
33 | [alignas](http://en.cppreference.com/w/cpp/language/alignas) instead.
34 |
35 | ## `-Bsymbolic`
36 |
37 | When targeting Android (but no other platform), GCC passed
38 | [-Bsymbolic](ftp://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html)
39 | to the linker by default. This is not a good default, so Clang does not
40 | do that. `-Bsymbolic` causes the following behavior change:
41 |
42 | ```c++
43 | // foo.cpp
44 | #include
45 |
46 | void foo() {
47 | std::cout << "Goodbye, world" << std::endl;
48 | }
49 |
50 | void bar() {
51 | foo();
52 | }
53 | ```
54 |
55 | ```c++
56 | // main.cpp
57 | #include
58 |
59 | extern void bar();
60 |
61 | void foo() {
62 | std::cout << "Hello, world\n";
63 | }
64 |
65 | int main(int, char**) {
66 | foo(); // Prints “Hello, world!”
67 | bar(); // Without -Bsymbolic, prints “Hello, world!” With -Bsymbolic, prints “Goodbye, world!”
68 | }
69 | ```
70 |
71 | In addition to not being the "expected" default behavior on all other
72 | platforms, this prevents symbol interposition (used by tools such
73 | as asan).
74 |
75 | You might however wish to add manually `-Bsymbolic` back because it can
76 | result in smaller ELF files because fewer relocations are needed. If you
77 | do want the non-`-Bsymbolic` behavior but would like fewer relocations,
78 | that can be achieved via `-fvisibility=hidden` (and manually exporting
79 | the symbols you want to be public, using the `JNI_EXPORT` macro in JNI
80 | code or `__attribute__ ((visibility("default")))` otherwise. Linker
81 | version scripts are an even more powerful mechanism for controlling
82 | exported symbols, but harder to use.
83 |
84 | ## Assembler issues
85 |
86 | For many years the problem of adjusting inline assembler to work with
87 | LLVM could be punted down the road by using `-fno-integrated-as` to fall
88 | back to the GNU Assembler (GAS). With the removal of GNU binutils from
89 | the NDK, such issues will now need to be addressed. We’ve collected
90 | some of the most common issues and their solutions/workarounds here.
91 |
92 | ### `.arch` or `.arch_extension` scope with `__asm__`
93 | GAS doesn’t scope `.arch` or `.arch_extension`, so you can have a global
94 | `__asm__(".arch foo")` that applies to the whole C/C++ source file,
95 | just like a bare `.arch` or `.arch_extension` directive would in a .S
96 | file. LLVM scopes these to the specific `__asm__` in which it occurs,
97 | so you’ll need to adapt your inline assembler, or build the whole file
98 | for the relevant arch variant.
99 |
100 | ### ARM `ADRL`
101 | GAS lets you use the `ADRL` pseudoinstruction to get the address of
102 | something too far away for a regular `ADR` to reference. This means
103 | that it expands to two instructions, which LLVM doesn’t support,
104 | so you’ll need to use a macro something like this instead:
105 | ```
106 | .macro ADRL reg:req, label:req
107 | add \reg, pc, #((\label - .L_adrl_\@) & 0xff00)
108 | add \reg, \reg, #((\label - .L_adrl_\@) - ((\label - .L_adrl_\@) & 0xff00))
109 | .L_adrl_\@:
110 | .endm
111 | ```
112 |
113 | ### ARM assembler syntactical strictness
114 | While GAS supports the older divided and newer unified syntax (selectable
115 | via `.syntax unified` and `.syntax divided`), LLVM only supports the
116 | newer unified syntax.
117 |
118 | As an example of where this matters, `LDR` has an optional type and the
119 | optional condition code allowed on all instructions. GAS allows these
120 | to come in either order when using divided syntax, but LLVM only allows
121 | them in the canonical order given in the ARM instruction reference (which
122 | is what “unified” syntax means). So continuing this example, GAS
123 | accepts both `LDRBEQ` and `LDREQB`, but LLVM only accepts `LDRBEQ` (with
124 | the condition code at the end, as the instruction appears in the manual).
125 |
126 | Most humans usually use this order anyway, but you’ll have to rearrange
127 | any instructions that don’t use the canonical order.
128 |
129 | ### ARM assembler implicit operands
130 | Some ARM instructions have restrictions that make some operands
131 | implicit. For example, the two target registers supplied to `LDREXD`
132 | must be consecutive. GAS would allow you to write `LDREXD R1, [R4]`
133 | because the other register _must_ be `R2`, but LLVM requires both
134 | registers to be explicitly stated, in this case `LDREXD R1, R2, [R4]`.
135 |
136 | ### ARM `.arm` or `.code 32` alignment
137 | Switching from Thumb to ARM mode implicitly forces 4-byte alignment
138 | with GAS but doesn’t with LLVM. You may need to use an explicit
139 | `.align`/`.balign`/`.p2align` directive in such cases.
140 |
141 | ### No `--defsym` command-line option
142 | GAS and LLVM implement their own conditional assembly mechanism with
143 | `.if`...`.endif` rather than the C preprocessor’s `#if`...`#endif`. The
144 | equivalent of `-DA=B` for `.if` is `-Wa,-defsym,A=B`, but GAS allowed
145 | `--defsym` instead of `-defsym`. LLVM requires `-defsym`.
146 |
147 | You might also prefer to just use the C preprocessor. If your assembly
148 | is in a .S file it is already being preprocessed. If your assembly
149 | is in a file with any other extension (including `.s` --- this is the
150 | difference between `.s` and `.S`), you’ll need to either rename it to
151 | `.S` or use the `-x assembler-with-cpp` flag to the compiler to override
152 | the file extension-based guess.
153 |
154 | ### No `.func`/`.endfunc`
155 | GAS ignores a request for obsolete STABS debugging information to be
156 | emitted using `.func` and `.endfunc`. Neither GAS nor LLVM actually
157 | support STABS, but LLVM rejects these meaningless directives. The fix
158 | is simply to remove them.
159 |
--------------------------------------------------------------------------------
/docs/ContinuousBuilds.md:
--------------------------------------------------------------------------------
1 | # Continuous Builds
2 |
3 | The NDK's continuous builds can be accessed by anyone at
4 | https://ci.android.com/builds/branches/aosp-master-ndk/grid. aosp-master-ndk is
5 | the development branch, and release branches can be selected with the branch
6 | name field at the top of the page.
7 |
8 | **Disclaimer**: These builds are **not** suitable for production use. This is
9 | just a continuous build. The amount of testing these builds have been put
10 | through is minimal. A successful build only means that our test suite *built*
11 | successfully on Linux and Darwin. Windows is not covered (the Windows build bots
12 | are actually Linux), and none of the tests have actually been run yet.
13 |
14 | ## NDK Branches
15 |
16 | ### NDK Canary
17 |
18 | This is the master (development) branch of the NDK. Corresponds to
19 | https://android.googlesource.com/platform/manifest/+/master-ndk.
20 |
21 | ### NDK rSOMETHING Release
22 |
23 | Release branches of the NDK. You can find the build number for the official
24 | release by examining the source.properties file in your NDK. The `Pkg.Revision`
25 | entry is in the format MAJOR.MINOR.BUILD (with beta information being appended
26 | if appropriate).
27 |
--------------------------------------------------------------------------------
/docs/HardFloatAbi.md:
--------------------------------------------------------------------------------
1 | ARM Hard Float ABI Removal
2 | ==========================
3 |
4 | We're removing support for the armeabi-v7a-hard ABI. Anyone targeting this ABI
5 | should target armeabi-v7a instead.
6 |
7 | Why?
8 |
9 | 1. People often use it because they think it's required to get
10 | floating point instructions, which is incorrect.
11 | 2. Most of the cases where people do see a performance improvement
12 | here are likely bugs/missed optimizations in either the compiler or
13 | the user's code, and hiding those means they won't get fixed.
14 | 3. It's full of bugs and fixing them and keeping them fixed isn't
15 | worth the benefit, especially in a world where you can avoid the
16 | problem entirely by making your app 64-bit.
17 |
18 | armeabi-v7a-hard is not a real ABI. No devices are built with this.
19 | Hard float code generation is already used in the armeabi-v7a ABI.
20 | The "hard float" variant only changes the function call ABI. That is,
21 | the floating point registers are used to pass floating point
22 | arguments rather than the integer registers.
23 |
24 | This ABI should only be beneficial if the workload consists of many
25 | math function calls, the math function is cheap enough that the call
26 | itself is expensive, and it's not being inlined. The bug here is that
27 | the call is not being inlined.
28 |
29 | There is a cost to keeping this functionality. The way this "ABI"
30 | works is by having an `__attribute__((pcs("aapcs")))` on every
31 | function that is part of the Android ABI and has floating point
32 | parameters (anything that is in the system libraries or zygote). If we
33 | miss one (and we do, often), the function will not be called
34 | correctly.
35 |
36 | I should note that the GCC docs explicitly state that linking
37 | -mfloat-abi=softfp and -mfloat-abi=hard is invalid:
38 | https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
39 |
40 | > Note that the hard-float and soft-float ABIs are not
41 | > link-compatible; you must compile your entire program with the same
42 | > ABI, and link with a compatible set of libraries.
43 |
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | TEMPLATE=user/dac_template.jd
2 | INPUT_FORMAT=markdown_github-hard_line_breaks+yaml_metadata_block
3 | OUTPUT_FORMAT=html5
4 |
5 | SRCS := $(wildcard user/*.md)
6 | INTERMEDIATES := $(patsubst user/%.md,.build/%.md,$(SRCS))
7 | OUTPUTS := $(patsubst user/%.md,html/user/%.jd,$(SRCS))
8 |
9 | $(info SRCS=$(SRCS))
10 | $(info INTERMEDIATES=$(INTERMEDIATES))
11 | $(info OUTPUTS=$(OUTPUTS))
12 |
13 | .SECONDARY: $(INTERMEDIATES)
14 |
15 | all: $(OUTPUTS) Makefile
16 |
17 | clean:
18 | rm -rf html
19 | rm -rf .build
20 |
21 | .build/%.md: user/%.md .build Makefile
22 | echo "---" > $@
23 | echo "title: '$(shell head -n1 $<)'" >> $@
24 | echo "..." >> $@
25 | tail -n +3 $< >> $@
26 |
27 | html/user/%.jd: .build/%.md $(TEMPLATE) html/user .build Makefile
28 | pandoc --template $(TEMPLATE) --from $(INPUT_FORMAT) --to $(OUTPUT_FORMAT) \
29 | --toc --toc-depth=2 $< --output $@ --standalone
30 |
31 | html/user: Makefile
32 | mkdir -p html/user
33 |
34 | .build: Makefile
35 | mkdir -p .build
36 |
--------------------------------------------------------------------------------
/docs/NdkGdbTesting.md:
--------------------------------------------------------------------------------
1 | ndk-gdb testing
2 | ===============
3 |
4 | Setup steps
5 | -----------
6 | 1. Sync the Android.mk samples with `git clone -b android-mk
7 | https://github.com/googlesamples/android-ndk.git`
8 | 2. Pick a sample app (e.g. Teapot), cd into its directory, and compile and
9 | install it to a device with `android update project -p . --target &&
10 | ndk-build && ant clean debug install`, where `` is an SDK target such
11 | as `android-23`.
12 | 3. Run ndk-gdb.py. This can be done in three ways:
13 | 1. Launch the application, and then run `ndk-gdb` from the app directory to
14 | attach the debugger.
15 | 2. Run `ndk-gdb --launch` to have ndk-gdb start the application's main
16 | activity.
17 | 3. Run `ndk-gdb --launch-activity ` to have ndk-gdb start a
18 | specific activity.
19 | 4. Test things!
20 |
21 | Relevant things to test
22 | -----------------------
23 | 1. Verify that backtraces are sensible.
24 | 2. Verify that breakpoints set before and after library load both work.
25 | (Using --launch vs. attaching after the application is running helps here.)
26 | 3. Verify that C++ stdlib pretty printers work (stlport and gnustl only).
27 | 4. Verify that ndk-gdb works with all valid combinations of app ABI support
28 | (defined in `APP_ABI` in Application.mk) and device ABI support.
29 | For example, test with the following combinations:
30 | 1. 32-bit device:
31 | 1. `APP_ABI := armeabi`
32 | 2. `APP_ABI := armeabi arm64-v8a`
33 | 2. 64-bit device:
34 | 1. `APP_ABI := armeabi`
35 | 2. `APP_ABI := armeabi arm64-v8a`
36 | 3. `APP_ABI := arm64-v8a`
37 |
--------------------------------------------------------------------------------
/docs/Onboarding.md:
--------------------------------------------------------------------------------
1 | # Onboarding
2 |
3 | The latest version of this document is available at
4 | https://android.googlesource.com/platform/ndk/+/master/docs/Onboarding.md.
5 |
6 | Welcome to the Android NDK! This guide will explain how to get started working
7 | on the NDK (if you want to work *with* the NDK, see the [user
8 | documentation](https://github.com/android/ndk/discussions)).
9 |
10 | Googlers: you'll also want to refer to
11 | [go/ndk-onboarding](http://go/ndk-onboarding) which will describe any details
12 | not relevant to external contributors. Non-Googlers, don't worry, you're not
13 | missing anything interesting, just boring things like instructions for how to
14 | work our release tooling.
15 |
16 | [TOC]
17 |
18 | ## Guides and docs
19 |
20 | 1. [Architecture](Architecture.md)
21 | 1. [Building](Building.md)
22 | 1. [Testing](Testing.md)
23 | 1. [Release process](https://github.com/android/ndk/wiki/NDK-Release-Process)
24 | 1. [Downloads](https://github.com/android/ndk/wiki)
25 | 1. [Bug tracker](https://github.com/android/ndk/issues)
26 | 1. [Android Studio/Gradle plugin bug tracker](https://developer.android.com/studio/report-bugs)
27 | 1. [Toolchain](Toolchains.md)
28 | 1. [Platform APIs](PlatformApis.md)
29 | 1. [Roadmap](Roadmap.md)
30 | 1. [Project boards](https://github.com/android/ndk/projects)
31 | 1. [Canary builds](ContinuousBuilds.md)
32 | 1. [User documentation](https://developer.android.com/ndk/index.html)
33 | 1. [Internal documentation](http://go/ndk)
34 |
35 | ## Mailing lists
36 |
37 | * [android-ndk Google Group] or [GitHub
38 | Discussions](https://github.com/android/ndk/discussions) for NDK discussion.
39 | * [android-ndk-announce Google Group] for release announcements.
40 |
41 | [android-ndk Google Group]: http://groups.google.com/group/android-ndk
42 | [android-ndk-announce Google Group]: http://groups.google.com/group/android-ndk-announce
43 |
44 | ## Chat
45 |
46 | * [#ndk on the r/AndroidDev Discord](https://discord.gg/8rjcbDbh6e)
47 |
--------------------------------------------------------------------------------
/docs/Toolchains.md:
--------------------------------------------------------------------------------
1 | # Working with the NDK Toolchains
2 |
3 | The latest version of this document is available at
4 | https://android.googlesource.com/platform/ndk/+/master/docs/Toolchains.md.
5 |
6 | The LLVM toolchain shipped in the NDK is not built as a part of the NDK build
7 | process. Instead is it built separately and checked into git as a prebuilt that
8 | is repackaged when shipped in the NDK.
9 |
10 | An artifact of the toolchain build is the distribution tarball. That artifact is
11 | unpacked into a location in the Android tree and checked in. The NDK build step
12 | for the toolchain copies that directory into the NDK and makes some
13 | modifications to make the toolchains suit the NDK rather than the platform.
14 | For example, non-NDK runtime libraries are deleted and the NDK sysroot is
15 | installed to the `sysroot` subdirectory of the toolchain so it can be found
16 | automatically by the compiler.
17 |
18 | Note: Any changes to either toolchain need to be tested in the platform *and*
19 | the NDK. The platform and the NDK both get their toolchains from the same build.
20 |
21 | TODO: This process is far too manual. `checkbuild.py` should be updated (or
22 | additional scripts added) to ease this process.
23 |
24 | ## Clang
25 |
26 | Clang's build process is described in the [Android LLVM Readme]. Note that Clang
27 | cannot be built from the NDK tree. The output tarball is extracted to
28 | `prebuilts/clang/host/$HOST/clang-$REVISION`. `checkbuild.py toolchain`
29 | repackages this into the NDK out directory.
30 |
31 | [Android LLVM Readme]: https://android.googlesource.com/toolchain/llvm_android/+/master/README.md
32 |
33 | ### Updating to a New Clang
34 |
35 | If you're updating the NDK to use a new release of the LLVM toolchain, do the
36 | following.
37 |
38 | Note: These steps need to be run after installing the new prebuilt from the
39 | build server to `prebuilts/clang` (see the [update-prebuilts.py]). The LLVM team
40 | will handle installing the new toolchain to prebuilts, but the NDK team usually
41 | makes the change to migrate to the new toolchain as described below.
42 |
43 | [update-prebuilts.py]: https://android.googlesource.com/toolchain/llvm_android/+/master/update-prebuilts.py
44 |
45 | ```bash
46 | # Edit ndk/toolchains.py and update `CLANG_VERSION`.
47 | $ ./checkbuild.py
48 | # ./run_tests.py
49 | ```
50 |
51 | ### Testing local llvm-toolchain changes with the NDK
52 |
53 | If you're working with unsubmitted changes to llvm-toolchain and want to test
54 | your LLVM changes in the NDK, do the following. If you're just updating the NDK
55 | to use a newer prebuilt LLVM, you don't need to do this part.
56 |
57 | ```bash
58 | $ export CLANG_PREBUILTS=`realpath ../prebuilts/clang/host/linux-x86`
59 | $ rm -r $CLANG_PREBUILTS/clang-dev
60 | # $LLVM_TOOLCHAIN refers to the root of your llvm-toolchain source directory. If
61 | # you have a tarball for the toolchain distribution, extract that to
62 | # $CLANG_PREBUILTS/clang-dev instead.
63 | $ cp -r $LLVM_TOOLCHAIN/out/install/$HOST/clang-dev $CLANG_PREBUILTS/
64 | # Update CLANG_VERSION in ndk/toolchains.py to clang-dev.
65 | $ ./checkbuild.py
66 | # Run tests. To run the NDK test suite, you will need to attach the
67 | # appropriately configured devices. The test tool will print warnings for
68 | # missing configurations.
69 | $ ./run_tests.py
70 | ```
71 |
72 | For details about running tests, see [Testing.md].
73 |
74 | [Testing.md]: Testing.md
75 |
76 | This installs the new Clang into the prebuilts directory so it can be included
77 | in the NDK.
78 |
79 | If you need to make changes to Clang after running the above steps, future
80 | updates can be done more quickly with:
81 |
82 | ```bash
83 | $ rm -r $CLANG_PREBUILTS/clang-dev
84 | $ tar xf path/to/clang-dev-linux-x86_64.bz2 -C $CLANG_PREBUILTS
85 | $ ./checkbuild.py toolchain
86 | # Run tests.
87 | ```
88 |
89 | We don't need to rebuild the whole NDK since we've already built most of it.
90 |
--------------------------------------------------------------------------------
/docs/UnifiedHeaders.md:
--------------------------------------------------------------------------------
1 | # Unified Headers
2 |
3 | [Issue #120](https://github.com/android-ndk/ndk/issues/120)
4 |
5 | Before NDK r14, we had a set of libc headers for each API version. In many cases
6 | these headers were incorrect. Many exposed APIs that didn't exist, and others
7 | didn't expose APIs that did.
8 |
9 | In NDK r14 (as an opt in feature) we unified these into a single set of headers,
10 | called unified headers. This single header path is used for *every* platform
11 | level. API level guards are handled with `#ifdef`. These headers can be found in
12 | [prebuilts/ndk/platform/sysroot].
13 |
14 | Unified headers are built directly from the Android platform, so they are up to
15 | date and correct (or at the very least, any bugs in the NDK headers will also be
16 | a bug in the platform headers, which means we're much more likely to find them).
17 |
18 | In r15 unified headers are used by default. In r16, the old headers have been
19 | removed.
20 |
21 | [prebuilts/ndk/headers]: https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include
22 |
23 | ## Supporting Unified Headers in Your Build System
24 |
25 | See the [Build System Maintainers] doc.
26 |
27 | [Build System Maintainers]: BuildSystemMaintainers.md
28 |
--------------------------------------------------------------------------------
/docs/UnifiedHeadersMigration.md:
--------------------------------------------------------------------------------
1 | Unified Headers Migration Notes
2 | ===============================
3 |
4 | When moving to unified headers, you may notice some differences. The unified
5 | headers represent nearly ten years of progress in the bionic header files, and
6 | in that time there have been a large number of cleanups (largely done for the
7 | sake of better compile times or better compatibility with other C libraries).
8 |
9 | To get an idea of what has changed, we can generate a standalone toolchain using
10 | both the unified headers and the deprecated headers, and then diff the list of
11 | files in `sysroot/usr/include`.
12 |
13 | List generated with:
14 |
15 | ```bash
16 | $ android-ndk-r15/build/tools/make_standalone_toolchain.py \
17 | --arch arm --api 26 --install-dir unified-toolchain
18 | $ android-ndk-r15/build/tools/make_standalone_toolchain.py \
19 | --arch arm --api 26 --deprecated-headers --install-dir deprecated-toolchain
20 | $ (cd unified-toolchain/sysroot/usr/include/ && find . -type f) | \
21 | grep -v 'linux-android' | sort > unified-include
22 | $ (cd deprecated-toolchain/sysroot/usr/include/ && find . -type f) | \
23 | sort > arm-26-include
24 | $ diff -u0 arm-26-include unified-include | grep -vP '^@@'
25 | ```
26 |
27 | The list below has been reorganized to group logical changes together for
28 | explanation.
29 |
30 | The same steps can be repeated with your target architecure or API level to get
31 | information tailored for your application.
32 |
33 | Note that the diff of the file contents themselves will be very large. Anything
34 | in the `linux/` directory will be very difficult to read, as those files contain
35 | an "AUTOGENERATED" warning every five lines. Those headers are the Linux UAPI
36 | headers, so they shouldn't contain any surprises.
37 |
38 | If your build is failing because a header has disappeared, use grep to search
39 | for the functions you're missing; they've likely only moved. If anything is
40 | actually missing, that may have been intentional, but could be an oversight.
41 | Search our [bugtracker] for both the name of the header and the functions you
42 | need. If you don't find anything (make sure you're searching *all* bugs, not
43 | just open ones), file a bug. It may be intentional, but the bug serves as
44 | documentation either way.
45 |
46 | One such header that was intentionally removed is ``. This was
47 | already not available for newer API levels when using the deprecated headers,
48 | but with unified headers it is not available for any API level. The NDK has
49 | support for C11 ``, so you should migrate to that.
50 |
51 | [bugtracker]: https://github.com/android-ndk/ndk/issues
52 |
53 |
54 | New APIs
55 | --------
56 |
57 | ```diff
58 | +./aaudio/AAudio.h
59 | +./android/hardware_buffer.h
60 | +./android/hardware_buffer_jni.h
61 | +./android/sharedmem.h
62 | +./android/sync.h
63 | +./GLES/egl.h
64 | ```
65 |
66 | The headers for these APIs will exist regardless of your target API level so you
67 | can access constants, prototypes, or types when conditionally accessing the API
68 | behind version checks with `dlsym`.
69 |
70 |
71 | Legacy Support
72 | --------------
73 |
74 | ```diff
75 | +./android/legacy_errno_inlines.h
76 | +./android/legacy_fenv_inlines_arm.h
77 | +./android/legacy_fenv_inlines_mips.h
78 | +./android/legacy_signal_inlines.h
79 | +./android/legacy_stdlib_inlines.h
80 | +./android/legacy_sys_stat_inlines.h
81 | +./android/legacy_sys_wait_inlines.h
82 | +./android/legacy_termios_inlines.h
83 | ```
84 |
85 | Many functions in older bionic headers were provided as inline functions. This
86 | is not standards compliant, so this has been fixed in later releases. These
87 | headers provide those inlines if you're targeting an older release.
88 |
89 |
90 | Linux UAPI Headers
91 | ------------------
92 |
93 | ```diff
94 | +linux/...
95 | -linux/...
96 | ```
97 |
98 | These are all changes in the Linux UAPI headers. These are the headers provided
99 | by the Linux kernel as a backward compatible kernel API. Any changes here are
100 | due to changes upstream.
101 |
102 |
103 | Everything Else
104 | ---------------
105 |
106 | The rest of the list is just the usual additions and cleanups to libc headers.
107 | Many headers were added, some were removed. Headers that were removed were
108 | typically removed because they were unique to Android, and we moved the contents
109 | to match other C libraries.
110 |
111 | ```diff
112 | +./android/set_abort_message.h
113 | +./android/versioning.h
114 | -./asm/a.out.h
115 | +./asm/unistd-common.h
116 | +./asm/unistd-eabi.h
117 | +./asm/unistd-oabi.h
118 | +./bits/auxvec.h
119 | +./bits/elf_arm64.h
120 | +./bits/elf_arm.h
121 | +./bits/elf_mips.h
122 | +./bits/elf_x86_64.h
123 | +./bits/elf_x86.h
124 | +./bits/fcntl.h
125 | +./bits/getopt.h
126 | +./bits/glibc-syscalls.h
127 | +./bits/ioctl.h
128 | +./bits/lockf.h
129 | +./bits/mbstate_t.h
130 | +./bits/posix_limits.h
131 | +./bits/pthread_types.h
132 | +./bits/sa_family_t.h
133 | +./bits/seek_constants.h
134 | +./bits/strcasecmp.h
135 | +./bits/struct_file.h
136 | +./bits/sysconf.h
137 | +./bits/timespec.h
138 | +./bits/wchar_limits.h
139 | +./bits/wctype.h
140 | +./cpio.h
141 | +./drm/amdgpu_drm.h
142 | +./drm/armada_drm.h
143 | +./drm/drm_fourcc.h
144 | +./drm/drm.h
145 | +./drm/drm_mode.h
146 | +./drm/drm_sarea.h
147 | +./drm/etnaviv_drm.h
148 | +./drm/exynos_drm.h
149 | +./drm/i810_drm.h
150 | +./drm/i915_drm.h
151 | +./drm/mga_drm.h
152 | +./drm/msm_drm.h
153 | +./drm/nouveau_drm.h
154 | +./drm/omap_drm.h
155 | +./drm/qxl_drm.h
156 | +./drm/r128_drm.h
157 | +./drm/radeon_drm.h
158 | +./drm/savage_drm.h
159 | +./drm/sis_drm.h
160 | +./drm/tegra_drm.h
161 | +./drm/vc4_drm.h
162 | +./drm/vgem_drm.h
163 | +./drm/via_drm.h
164 | +./drm/virtgpu_drm.h
165 | +./drm/vmwgfx_drm.h
166 | +./error.h
167 | +./ifaddrs.h
168 | +./langinfo.h
169 | -./machine/elf_machdep.h
170 | -./machine/endian.h
171 | -./machine/exec.h
172 | -./machine/ieee.h
173 | -./machine/wchar_limits.h
174 | +./misc/cxl.h
175 | +./mtd/inftl-user.h
176 | +./mtd/mtd-abi.h
177 | +./mtd/mtd-user.h
178 | +./mtd/nftl-user.h
179 | +./mtd/ubi-user.h
180 | -./net/ethertypes.h
181 | -./net/if_ether.h
182 | -./net/if_ieee1394.h
183 | -./net/if_types.h
184 | -./nsswitch.h
185 | +./nl_types.h
186 | -./pathconf.h
187 | +./pty.h
188 | +./rdma/cxgb3-abi.h
189 | +./rdma/cxgb4-abi.h
190 | +./rdma/hfi/hfi1_user.h
191 | +./rdma/hns-abi.h
192 | +./rdma/ib_user_cm.h
193 | +./rdma/ib_user_mad.h
194 | +./rdma/ib_user_sa.h
195 | +./rdma/ib_user_verbs.h
196 | +./rdma/mlx4-abi.h
197 | +./rdma/mlx5-abi.h
198 | +./rdma/mthca-abi.h
199 | +./rdma/nes-abi.h
200 | +./rdma/ocrdma-abi.h
201 | +./rdma/qedr-abi.h
202 | +./rdma/rdma_netlink.h
203 | +./rdma/rdma_user_cm.h
204 | +./rdma/rdma_user_rxe.h
205 | +./rdma/vmw_pvrdma-abi.h
206 | +./scsi/cxlflash_ioctl.h
207 | +./scsi/fc/fc_els.h
208 | +./scsi/fc/fc_fs.h
209 | +./scsi/fc/fc_gs.h
210 | +./scsi/fc/fc_ns.h
211 | +./scsi/scsi_bsg_fc.h
212 | +./scsi/scsi.h
213 | +./scsi/scsi_ioctl.h
214 | +./scsi/scsi_netlink_fc.h
215 | +./scsi/scsi_netlink.h
216 | +./scsi/scsi_proto.h
217 | +./scsi/sg.h
218 | -./sgtty.h
219 | +./sound/asequencer.h
220 | +./sound/asoc.h
221 | +./sound/asound_fm.h
222 | +./sound/asound.h
223 | +./sound/compress_offload.h
224 | +./sound/compress_params.h
225 | +./sound/emu10k1.h
226 | +./sound/firewire.h
227 | +./sound/hdsp.h
228 | +./sound/hdspm.h
229 | +./sound/sb16_csp.h
230 | +./sound/sfnt_info.h
231 | +./sound/snd_sst_tokens.h
232 | +./sound/tlv.h
233 | +./sound/usb_stream.h
234 | +./stdio_ext.h
235 | +./syscall.h
236 | -./sys/cdefs_elf.h
237 | +./sysexits.h
238 | +./sys/fcntl.h
239 | -./sys/glibc-syscalls.h
240 | -./sys/ioctl_compat.h
241 | +./sys/quota.h
242 | -./sys/socketcalls.h
243 | -./sys/syslimits.h
244 | +./sys/syslog.h
245 | +./sys/_system_properties.h
246 | -./sys/ttychars.h
247 | -./sys/ttydev.h
248 | +./sys/unistd.h
249 | -./sys/utime.h
250 | +./tar.h
251 | -./thread_db.h
252 | -./util.h
253 | +./video/edid.h
254 | +./video/sisfb.h
255 | +./video/uvesafb.h
256 | +./wait.h
257 | +./xen/evtchn.h
258 | +./xen/gntalloc.h
259 | +./xen/gntdev.h
260 | +./xen/privcmd.h
261 | ```
262 |
--------------------------------------------------------------------------------
/docs/UpdatingDocumentation.md:
--------------------------------------------------------------------------------
1 | Updating Documentation
2 | ======================
3 |
4 | The documentation in [docs/user](user) is a subset of the guides that are
5 | present on the [developer website]. It will some day be all the guides, but
6 | we're doing this piece by piece.
7 |
8 | [developer website]: https://developer.android.com/ndk/guides/index.html
9 |
10 | To update the documentation, edit the appropriate Markdown file. For
11 | https://developer.android.com/ndk/guides/StandaloneToolchain.html, edit
12 | [docs/user/StandaloneToolchain.md](user/StandaloneToolchain.md). The page layout
13 | is handled by [docs/user/dac\_template.jd](user/dac_template.jd), but that
14 | should not be altered unless the layout of DAC is changed.
15 |
16 | The docs are not automatically pushed to the website. A Googler will need to run
17 | `scripts/update_dac.py` to publish changes. Googlers: simply run this script
18 | with the path to the root of your docs tree as the argument, make the commit,
19 | and upload the patch.
20 |
--------------------------------------------------------------------------------
/docs/changelogs/Changelog-r20.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Report issues to [GitHub].
4 |
5 | For Android Studio issues, follow the docs on the [Android Studio site].
6 |
7 | [GitHub]: https://github.com/android-ndk/ndk/issues
8 | [Android Studio site]: http://tools.android.com/filing-bugs
9 |
10 | ## Announcements
11 |
12 | * [LLD](https://lld.llvm.org/) is now available for testing. AOSP is in the
13 | process of switching to using LLD by default and the NDK will follow
14 | (timeline unknown). Test LLD in your app by passing `-fuse-ld=lld` when
15 | linking.
16 |
17 | * The Play Store will require 64-bit support when uploading an APK beginning in
18 | August 2019. Start porting now to avoid surprises when the time comes. For
19 | more information, see [this blog post](https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html).
20 |
21 | ## Changes
22 |
23 | * Updated Clang to r346389c.
24 | * Updated libc++ to r350972.
25 | * [Issue 908]: `LOCAL_LDFLAGS` now take precedence over `APP_LDFLAGS`.
26 |
27 | [Issue 908]: https://github.com/android-ndk/ndk/issues/908
28 |
29 | ## Known Issues
30 |
31 | * This is not intended to be a comprehensive list of all outstanding bugs.
32 | * [Issue 360]: `thread_local` variables with non-trivial destructors will cause
33 | segfaults if the containing library is `dlclose`ed on devices running M or
34 | newer, or devices before M when using a static STL. The simple workaround is
35 | to not call `dlclose`.
36 | * [Issue 70838247]: Gold emits broken debug information for AArch64. AArch64
37 | still uses BFD by default.
38 | * [Issue 855]: LLD may hang on Windows when using multithreaded linking.
39 | ndk-build will automatically disable multithreaded linking in this situation,
40 | but CMake users and custom build systems should pass `-Wl,--no-threads` when
41 | using LLD on Windows. The other linkers and operating systems are unaffected.
42 | * [Issue 884]: Third-party build systems must pass `-fno-addrsig` to Clang for
43 | compatibility with binutils. ndk-build, CMake, and standalone toolchains
44 | handle this automatically.
45 | * [Issue 888]: lld does not support compressed symbols on Windows. Clang also
46 | cannot generate compressed symbols on Windows, but this can be a problem when
47 | using artifacts built from Darwin or Linux.
48 | * [Issue 906]: Clang does not pass `-march=armv7-a` to the assembler when using
49 | `-fno-integrated-as`. This results in the assembler generating ARMv5
50 | instructions. Note that by default Clang uses the integrated assembler which
51 | does not have this problem. To workaround this issue, explicitly use
52 | `-march=armv7-a` when building for 32-bit ARM with the non-integrated
53 | assembler, or use the integrated assembler. ndk-build and CMake already
54 | contain these workarounds.
55 | * [Issue 906]: Clang does not pass `-march=armv7-a` to the assembler when using
56 | `-fno-integrated-as`. This results in the assembler generating ARMv5
57 | instructions. Note that by default Clang uses the integrated assembler which
58 | does not have this problem. To workaround this issue, explicitly use
59 | `-march=armv7-a` when building for 32-bit ARM with the non-integrated
60 | assembler, or use the integrated assembler. ndk-build and CMake already
61 | contain these workarounds.
62 | * [Issue 988]: Exception handling when using ASan via wrap.sh can crash. To
63 | workaround this issue when using libc++_shared, ensure that your
64 | application's libc++_shared.so is in `LD_PRELOAD` in your `wrap.sh` as in the
65 | following example:
66 |
67 | ```bash
68 | #!/system/bin/sh
69 | HERE="$(cd "$(dirname "$0")" && pwd)"
70 | export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
71 | ASAN_LIB=$(ls $HERE/libclang_rt.asan-*-android.so)
72 | if [ -f "$HERE/libc++_shared.so" ]; then
73 | # Workaround for https://github.com/android-ndk/ndk/issues/988.
74 | export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
75 | else
76 | export LD_PRELOAD="$ASAN_LIB"
77 | fi
78 | "$@"
79 | ```
80 |
81 | There is no known workaround for libc++_static.
82 |
83 | Note that because this is a platform bug rather than an NDK bug this
84 | workaround will be necessary for this use case to work on all devices until
85 | at least Android R.
86 | * [Issue 1004]: Clang outputs debug info with bad line number info when
87 | compiling for ARM64 and `-O0` (no optimizations). Third-party build systems
88 | can pass `-fno-experimental-isel` to Clang to work around this issue.
89 | * This version of the NDK is incompatible with the Android Gradle plugin
90 | version 3.0 or older. If you see an error like
91 | `No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android`,
92 | update your project file to [use plugin version 3.1 or newer]. You will also
93 | need to upgrade to Android Studio 3.1 or newer.
94 |
95 | [Issue 360]: https://github.com/android-ndk/ndk/issues/360
96 | [Issue 70838247]: https://issuetracker.google.com/70838247
97 | [Issue 855]: https://github.com/android-ndk/ndk/issues/855
98 | [Issue 884]: https://github.com/android-ndk/ndk/issues/884
99 | [Issue 888]: https://github.com/android-ndk/ndk/issues/888
100 | [Issue 906]: https://github.com/android-ndk/ndk/issues/906
101 | [Issue 988]: https://github.com/android-ndk/ndk/issues/988
102 | [Issue 1004]: https://github.com/android-ndk/ndk/issues/1004
103 | [use plugin version 3.1 or newer]: https://developer.android.com/studio/releases/gradle-plugin#updating-plugin
104 |
--------------------------------------------------------------------------------
/docs/changelogs/Changelog-r22.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Report issues to [GitHub].
4 |
5 | For Android Studio issues, follow the docs on the [Android Studio site].
6 |
7 | [GitHub]: https://github.com/android/ndk/issues
8 | [Android Studio site]: http://tools.android.com/filing-bugs
9 |
10 | ## Announcements
11 |
12 | * GNU binutils is deprecated and will be removed in an upcoming NDK release.
13 | Note that the GNU assembler (`as`) **is** a part of this. If you are building
14 | with `-fno-integrated-as`, file bugs if anything is preventing you from
15 | removing that flag. If you're using `as` directly, use `clang` instead.
16 |
17 | * [LLD](https://lld.llvm.org/) is now the default linker. ndk-build and our
18 | CMake toolchain file have also migrated to using llvm-ar and llvm-strip.
19 |
20 | See the Changes section below for more information.
21 |
22 | ## r22b
23 |
24 | * [Issue 1377]: Fix Clang backend crash in register scavenging.
25 | * [Issue 1388]: Fixed LLVM's incorrect conversion to list files for long command
26 | lines on Windows.
27 | * [Issue 1391]: Fixed missing symbols from libz.a.
28 | * [Issue 1427]: Fixed Clang auto-detection for CMake 3.19 and older for Windows.
29 |
30 | [Issue 1377]: https://github.com/android/ndk/issues/1377
31 | [Issue 1388]: https://github.com/android/ndk/issues/1388
32 | [Issue 1391]: https://github.com/android/ndk/issues/1391
33 | [Issue 1427]: https://github.com/android/ndk/issues/1427
34 |
35 | ## Changes
36 |
37 | * Updated LLVM to r399163b, based on LLVM 11 development.
38 | * [Issue 829]: Fixed issue with `__attribute__((visibility("hidden")))`
39 | symbols sometimes not being hidden.
40 | * [Issue 1149]: Fixed Clang crash with `#pragma detect_mismatch`.
41 | * [Issue 1212]: Fixed llvm-strip to match GNU behavior for removing file
42 | symbols.
43 | * [Issue 1248]: Fixed LLD Neon crash.
44 | * [Issue 1303]: Fixed Neon intrinsic optimizer crash.
45 |
46 | * Updated make to 4.3.
47 |
48 | * Updated libc++, libc++abi, and libunwind to
49 | https://github.com/llvm/llvm-project/commit/52ec983895436089c5be0b0c4d967423db16045b.
50 |
51 | * [Issue 609]: `std::filesystem` support is now included. There are two known
52 | issues:
53 | * [Issue 1258]: `std::filesystem::perm_options::nofollow` may not be
54 | honored on old devices.
55 | * [Issue 1260]: `std::filesystem::canonical` will incorrectly succeed when
56 | passed a non-existent path on old devices.
57 |
58 | * [Issue 843]: `llvm-strip` is now used instead of `strip` to avoid breaking
59 | RelRO with LLD. Note that the Android Gradle Plugin performs its own
60 | stripping, so most users will need to upgrade to Android Gradle Plugin
61 | version 4.0 or newer to get the fix.
62 |
63 | * [Issue 1130]: Fixed undefined references to new that could occur when building
64 | for APIs prior to 21 and the static libc++. Note that LLD appears to have been
65 | unaffected, but the problem is still present for ndk-build when using the
66 | deprecated linkers.
67 |
68 | * [Issue 1139]: `native_app_glue` now hooks up the `APP_CMD_WINDOW_RESIZED`,
69 | `APP_CMD_WINDOW_REDRAW_NEEDED`, and `APP_CMD_CONTENT_RECT_CHANGED` messages.
70 |
71 | * [Issue 1196]: Backtraces for crashes on devices older than API 29 are now
72 | correct when using LLD if using ndk-build or the CMake toolchain file. If
73 | using a different system and targeting devices older than API 29, use
74 | `-Wl,--no-rosegment` when linking. See the [Build System Maintainers Guide]
75 | for more information.
76 |
77 | * The deprecated `/platforms` and `/sysroot` directories have been
78 | removed. These directories were merged and relocated into the toolchain during
79 | r19. The location of these contents should not be relevant to anyone,
80 | including build systems, since the toolchain handles them implicitly. If you
81 | are using a build system that hasn't adapted to the changes introduced in NDK
82 | r19, file a bug with your build system maintainer. See the [Build System
83 | Maintainers Guide] for information on using the NDK in your own build system.
84 |
85 | * `llvm-ar` is now used instead of `ar`.
86 |
87 | * [Issue 1200]: Fixed an issue with using `dlclose` with libraries using
88 | `thread_local` with non-trivial destructors and the static libc++.
89 |
90 | * The legacy libc++ linker scripts in `/sources/cxx-stl/llvm-libc++` have
91 | been removed. The linkers scripts in the toolchain should be used instead as
92 | described by the [Build System Maintainers Guide].
93 |
94 | * LLD is now used by default. If your build is not yet compatible with LLD, you
95 | can continue using the deprecated linkers, set `APP_LD=deprecated` for
96 | ndk-build, `ANDROID_LD=deprecated` for CMake, or use an explicit
97 | `-fuse-ld=gold` or `-fuse-ld=bfd` in your custom build system. If you
98 | encounter issues be sure to file a bug, because this will not be an option in
99 | a subsequent release.
100 |
101 | Note that [Issue 843] will affect builds using LLD with binutils strip and
102 | objcopy as opposed to llvm-strip and llvm-objcopy.
103 |
104 | * ndk-gdb now uses lldb as the debugger. gdb is deprecated and will be removed in
105 | a future release. To fall back to gdb, use --no-lldb option. But please
106 | [file a bug] explaining why you couldn't use lldb.
107 |
108 | [Build System Maintainers Guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
109 | [Issue 609]: https://github.com/android/ndk/issues/609
110 | [Issue 829]: https://github.com/android/ndk/issues/829
111 | [Issue 1139]: https://github.com/android/ndk/issues/1139
112 | [Issue 1149]: https://github.com/android/ndk/issues/1149
113 | [Issue 1196]: https://github.com/android/ndk/issues/1196
114 | [Issue 1200]: https://github.com/android/ndk/issues/1200
115 | [Issue 1212]: https://github.com/android/ndk/issues/1212
116 | [Issue 1248]: https://github.com/android/ndk/issues/1248
117 | [Issue 1258]: https://github.com/android/ndk/issues/1258
118 | [Issue 1260]: https://github.com/android/ndk/issues/1260
119 | [Issue 1303]: https://github.com/android/ndk/issues/1303
120 | [file a bug]: https://github.com/android/ndk/issues/new/choose
121 |
122 | ## Known Issues
123 |
124 | * This is not intended to be a comprehensive list of all outstanding bugs.
125 | * [Issue 360]: `thread_local` variables with non-trivial destructors will cause
126 | segfaults if the containing library is `dlclose`ed on devices running M or
127 | newer, or devices before M when using a static STL. The simple workaround is
128 | to not call `dlclose`.
129 | * [Issue 906]: Clang does not pass `-march=armv7-a` to the assembler when using
130 | `-fno-integrated-as`. This results in the assembler generating ARMv5
131 | instructions. Note that by default Clang uses the integrated assembler which
132 | does not have this problem. To workaround this issue, explicitly use
133 | `-march=armv7-a` when building for 32-bit ARM with the non-integrated
134 | assembler, or use the integrated assembler. ndk-build and CMake already
135 | contain these workarounds.
136 | * [Issue 988]: Exception handling when using ASan via wrap.sh can crash. To
137 | workaround this issue when using libc++_shared, ensure that your
138 | application's libc++_shared.so is in `LD_PRELOAD` in your `wrap.sh` as in the
139 | following example:
140 |
141 | ```bash
142 | #!/system/bin/sh
143 | HERE="$(cd "$(dirname "$0")" && pwd)"
144 | export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
145 | ASAN_LIB=$(ls $HERE/libclang_rt.asan-*-android.so)
146 | if [ -f "$HERE/libc++_shared.so" ]; then
147 | # Workaround for https://github.com/android/ndk/issues/988.
148 | export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
149 | else
150 | export LD_PRELOAD="$ASAN_LIB"
151 | fi
152 | "$@"
153 | ```
154 |
155 | There is no known workaround for libc++_static.
156 |
157 | Note that because this is a platform bug rather than an NDK bug this
158 | workaround will be necessary for this use case to work on all devices until
159 | at least Android R.
160 | * [Issue 1130]: When using `c++_static` and the deprecated linker with ndk-build
161 | with an `APP_PLATFORM` below 21, undefined references to operator new may
162 | occur. The fix is to use LLD.
163 | * This version of the NDK is incompatible with the Android Gradle plugin
164 | version 3.0 or older. If you see an error like
165 | `No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android`,
166 | update your project file to [use plugin version 3.1 or newer]. You will also
167 | need to upgrade to Android Studio 3.1 or newer.
168 | * [Issue 843]: Using LLD with binutils `strip` or `objcopy` breaks RelRO. Use
169 | `llvm-strip` and `llvm-objcopy` instead. This issue has been resolved in
170 | Android Gradle Plugin version 4.0 (for non-Gradle users, the fix is also in
171 | ndk-build and our CMake toolchain file), but may affect other build systems.
172 |
173 | [Issue 360]: https://github.com/android/ndk/issues/360
174 | [Issue 843]: https://github.com/android/ndk/issues/843
175 | [Issue 906]: https://github.com/android/ndk/issues/906
176 | [Issue 988]: https://github.com/android/ndk/issues/988
177 | [Issue 1130]: https://github.com/android/ndk/issues/1130
178 | [use plugin version 3.1 or newer]: https://developer.android.com/studio/releases/gradle-plugin#updating-plugin
179 |
--------------------------------------------------------------------------------
/docs/changelogs/Changelog-r24.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Report issues to [GitHub].
4 |
5 | For Android Studio issues, follow the docs on the [Android Studio site].
6 |
7 | If you're a build system maintainer that needs to use the tools in the NDK
8 | directly, see the [build system maintainers guide].
9 |
10 | [GitHub]: https://github.com/android/ndk/issues
11 | [Android Studio site]: http://tools.android.com/filing-bugs
12 | [build system maintainers]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
13 |
14 | ## Announcements
15 |
16 | * The GNU Assembler (GAS), has been removed. If you were building with
17 | `-fno-integrated-as` you'll need to remove that flag. See
18 | [Clang Migration Notes] for advice on making assembly compatible with LLVM.
19 |
20 | * GDB has been removed. Use LLDB instead. Note that `ndk-gdb` uses LLDB by
21 | default, and Android Studio has only ever supported LLDB.
22 |
23 | * Jelly Bean (APIs 16, 17, and 18) is no longer supported. The minimum OS
24 | supported by the NDK is KitKat (API level 19).
25 |
26 | * Non-Neon devices are no longer supported. A very small number of very old
27 | devices do not support Neon so most apps will not notice aside from the
28 | performance improvement.
29 |
30 | * RenderScript build support has been removed. RenderScript was
31 | [deprecated](https://developer.android.com/about/versions/12/deprecations#renderscript)
32 | in Android 12. If you have not finished migrating your apps away from
33 | RenderScript, NDK r23 LTS can be used.
34 |
35 | [Clang Migration Notes]: https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md
36 |
37 | ## r24b
38 |
39 | * [Issue 1693]: The NDK's toolchain file for CMake (`android.toolchain.cmake`)
40 | defaults to the legacy toolchain file for all versions of CMake. The new
41 | toolchain file can still be enabled using
42 | `-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF`.
43 |
44 | [Issue 1693]: https://github.com/android/ndk/issues/1693
45 |
46 | ## Changes
47 |
48 | * Includes Android 12L APIs.
49 | * Updated LLVM to clang-r437112b, based on LLVM 14 development.
50 | * [Issue 1590]: Fix LLDB help crash.
51 | * [Issue 1108]: Removed `mbstowcs` and `wcstombs` from the pre-API 21 stubs and
52 | moved the implementation to `libandroid_support` to fix those APIs on old
53 | devices.
54 | * [Issue 1299]: Additional Apple M1 support:
55 | * [Issue 1410]: Fixed incorrect host tool directory identification in
56 | ndk-build on M1 macs.
57 | * [Issue 1544]: LLVM tools are now universal binaries.
58 | * [Issue 1546]: Make is now a universal binary.
59 | * [Issue 1479]: Added `LOCAL_BRANCH_PROTECTION` option to ndk-build for using
60 | `-mbranch-protection` with aarch64 without breaking other ABIs. Example use:
61 | `LOCAL_BRANCH_PROTECTION := standard`.
62 | * [Issue 1492]: Windows Make now works with `-O`, and ndk-build now uses it by
63 | default.
64 | * [Issue 1559]: Added `LOCAL_ALLOW_MISSING_PREBUILT` option to
65 | `PREBUILT_SHARED_LIBRARY` and `PREBUILT_STATIC_LIBRARY` which defers failures
66 | for missing prebuilts to build time. This enables use cases within AGP where
67 | one module provides "pre" built libraries to another module.
68 | * [Issue 1587]: ndk-stack is now tolerant of unsorted zip infos.
69 | * [Issue 1589]: Fixed broken stack traces on API 29 devices when using a
70 | minSdkVersion of 29.
71 | * [Issue 1593]: Improved ndk-which to fall back to LLVM tools when the GNU names
72 | are used. For example, `ndk-which strip` will now return the path to
73 | `llvm-strip` instead of nothing.
74 | * [Issue 1610]: Fixed handling of `ANDROID_NATIVE_API_LEVEL` in the new CMake
75 | toolchain file.
76 | * [Issue 1618]: Corrected `CMAKE_ANDROID_EXCEPTIONS` behavior for the new CMake
77 | toolchain file.
78 | * [Issue 1623]: Fixed behavior of the legacy CMake toolchain file when used with
79 | new versions of CMake (incompatible `-gcc-toolchain` argument).
80 | * [Issue 1656]: The new CMake toolchain file now ignores `ANDROID_ARM_MODE` when
81 | it is passed for ABIs other than armeabi-v7a like the legacy toolchain file
82 | did. With CMake 3.22 it is an error to set `CMAKE_ANDROID_ARM_MODE` for other
83 | ABIs, so this fixes a potential incompatibility between the legacy and new
84 | toolchains when using CMake 3.22+.
85 | * Removed `make-standalone-toolchain.sh`. This was broken in a previous release
86 | and it was unnoticed, so it seems unused. `make_standalone_toolchain.py`
87 | remains, but neither has been needed since NDK r19 since the toolchain can be
88 | invoked directly.
89 |
90 | [Issue 1108]: https://github.com/android/ndk/issues/1108
91 | [Issue 1299]: https://github.com/android/ndk/issues/1299
92 | [Issue 1410]: https://github.com/android/ndk/issues/1410
93 | [Issue 1479]: https://github.com/android/ndk/issues/1479
94 | [Issue 1492]: https://github.com/android/ndk/issues/1492
95 | [Issue 1544]: https://github.com/android/ndk/issues/1544
96 | [Issue 1546]: https://github.com/android/ndk/issues/1546
97 | [Issue 1559]: https://github.com/android/ndk/issues/1559
98 | [Issue 1587]: https://github.com/android/ndk/issues/1587
99 | [Issue 1589]: https://github.com/android/ndk/issues/1589
100 | [Issue 1590]: https://github.com/android/ndk/issues/1590
101 | [Issue 1593]: https://github.com/android/ndk/issues/1593
102 | [Issue 1610]: https://github.com/android/ndk/issues/1610
103 | [Issue 1618]: https://github.com/android/ndk/issues/1618
104 | [Issue 1623]: https://github.com/android/ndk/issues/1623
105 | [Issue 1656]: https://github.com/android/ndk/issues/1656
106 |
107 | ## Known Issues
108 |
109 | This is not intended to be a comprehensive list of all outstanding bugs.
110 |
111 | * [Issue 360]: `thread_local` variables with non-trivial destructors will cause
112 | segfaults if the containing library is `dlclose`ed. This was fixed in API 28,
113 | but code running on devices older than API 28 will need a workaround. The
114 | simplest fix is to **stop calling `dlclose`**. If you absolutely must continue
115 | calling `dlclose`, see the following table:
116 |
117 | | | Pre-API 23 | APIs 23-27 | API 28+ |
118 | | ----------------- | -------------------- | ------------- | ------- |
119 | | No workarounds | Works for static STL | Broken | Works |
120 | | `-Wl,-z,nodelete` | Works for static STL | Works | Works |
121 | | No `dlclose` | Works | Works | Works |
122 |
123 | If your code must run on devices older than M (API 23) and you cannot use the
124 | static STL (common), **the only fix is to not call `dlclose`**, or to stop
125 | using `thread_local` variables with non-trivial destructors.
126 |
127 | If your code does not need to run on devices older than API 23 you can link
128 | with `-Wl,-z,nodelete`, which instructs the linker to ignore `dlclose` for
129 | that library. You can backport this behavior by not calling `dlclose`.
130 |
131 | The fix in API 28 is the standardized inhibition of `dlclose`, so you can
132 | backport the fix to older versions by not calling `dlclose`.
133 |
134 | * [Issue 988]: Exception handling when using ASan via wrap.sh can crash. To
135 | workaround this issue when using libc++_shared, ensure that your application's
136 | libc++_shared.so is in `LD_PRELOAD` in your `wrap.sh` as in the following
137 | example:
138 |
139 | ```bash
140 | #!/system/bin/sh
141 | HERE="$(cd "$(dirname "$0")" && pwd)"
142 | export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
143 | ASAN_LIB=$(ls $HERE/libclang_rt.asan-*-android.so)
144 | if [ -f "$HERE/libc++_shared.so" ]; then
145 | # Workaround for https://github.com/android/ndk/issues/988.
146 | export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
147 | else
148 | export LD_PRELOAD="$ASAN_LIB"
149 | fi
150 | "$@"
151 | ```
152 |
153 | There is no known workaround for libc++_static.
154 |
155 | Note that because this is a platform bug rather than an NDK bug this cannot be
156 | fixed with an NDK update. This workaround will be necessary for code running
157 | on devices that do not contain the fix, and the bug has not been fixed even in
158 | the latest release of Android.
159 |
160 | [Issue 360]: https://github.com/android/ndk/issues/360
161 | [Issue 988]: https://github.com/android/ndk/issues/988
162 |
--------------------------------------------------------------------------------
/docs/changelogs/Changelog-r25.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Report issues to [GitHub].
4 |
5 | For Android Studio issues, follow the docs on the [Android Studio site].
6 |
7 | If you're a build system maintainer that needs to use the tools in the NDK
8 | directly, see the [build system maintainers guide].
9 |
10 | [GitHub]: https://github.com/android/ndk/issues
11 | [Android Studio site]: http://tools.android.com/filing-bugs
12 | [build system maintainers guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
13 |
14 |
15 | ## Announcements
16 |
17 | * Support for KitKat (APIs 19 and 20) is planned to be removed in the next NDK
18 | release. The minimum OS supported by the NDK for r26 will be Lollipop (API
19 | level 21). See [Issue 1751] for details.
20 |
21 | [Issue 1751]: https://github.com/android/ndk/issues/1751
22 |
23 | ## r25c
24 |
25 | * Updated LLVM to clang-r450784d1, based on LLVM 14 development.
26 | * [Issue 1797]: Fixed LLDB handling of forward slashes in absolute paths on
27 | Windows.
28 | * [Issue 1832]: Improvements to aarch64 vector code generation.
29 | * [Issue 1813]: `-Wl,--gc-sections` is no longer set by default for debug
30 | builds. This behavior was removed because it could cause the linker to remove
31 | functions that may be useful to evaluate during debugging. The new CMake
32 | toolchain file (`-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF`, not the default
33 | behavior) does not include this fix because it requires a CMake fix first.
34 | * [Issue 1757]: Updated simpleperf. Includes fix for signing denial when run on
35 | macOS.
36 |
37 | [Issue 1797]: https://github.com/android/ndk/issues/1797
38 | [Issue 1813]: https://github.com/android/ndk/issues/1813
39 | [Issue 1832]: https://github.com/android/ndk/issues/1832
40 |
41 | ## r25b
42 |
43 | * [Issue 1739]: Fixed C compatibility issue in `amidi/AMidi.h`.
44 | * [Issue 1740]: Fixed the legacy toolchain when using CMake's `Release` build
45 | configuration. Since r23b it has not be receiving any optimization flag. It
46 | will now receive `-O3`. If you're building with AGP and haven't overridden
47 | AGP's default CMake modes, this change does not affect you, as AGP uses
48 | `RelWithDebInfo` by default.
49 | * [Issue 1744]: Fixes ASan wrap.sh file to support 32-bit apps on 64-bit
50 | devices.
51 |
52 | [Issue 1739]: https://github.com/android/ndk/issues/1739
53 | [Issue 1740]: https://github.com/android/ndk/issues/1740
54 | [Issue 1744]: https://github.com/android/ndk/issues/1744
55 |
56 | ## Changes
57 |
58 | * Includes Android 13 APIs.
59 | * Updated LLVM to clang-r450784d, based on LLVM 14 development.
60 | * [Issue 1455]: Improved display of Android API levels in Clang diagnostics.
61 | * [Issue 1608]: Fixed crash in vector conversions.
62 | * [Issue 1710]: Fixed compiler crash caused by invalid `-march` values.
63 | * Eliminate duplicate static libraries in API-versioned sysroot directories.
64 | This reduces the uncompressed size of the NDK by 500 MB.
65 | * Strip some binaries and libraries. This reduces the uncompressed size of
66 | the NDK by 300 MB.
67 | * Remove python2. All scripts now use python3.
68 | * [Issue 933]: Updated reference ASan wrap.sh to support attaching the Java
69 | debugger.
70 | * [Issue 1334]: Improved argument escaping for compile_commands.json files
71 | generated by ndk-build.
72 | * [Issue 1634]: Fixed the build rule for the libshaderc_combined target.
73 | * [Issue 1693]: The NDK's toolchain file for CMake (`android.toolchain.cmake`)
74 | defaults to the legacy toolchain file for all versions of CMake. The new
75 | toolchain file can still be enabled using
76 | `-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF`.
77 | * [Issue 1717]: Arranged for --gc-sections to be passed to the linker when
78 | building shared libraries.
79 |
80 | [Issue 933]: https://github.com/android/ndk/issues/933
81 | [Issue 1334]: https://github.com/android/ndk/issues/1334
82 | [Issue 1455]: https://github.com/android/ndk/issues/1455
83 | [Issue 1608]: https://github.com/android/ndk/issues/1608
84 | [Issue 1634]: https://github.com/android/ndk/issues/1634
85 | [Issue 1693]: https://github.com/android/ndk/issues/1693
86 | [Issue 1710]: https://github.com/android/ndk/issues/1710
87 | [Issue 1717]: https://github.com/android/ndk/issues/1717
88 |
89 | ## Known Issues
90 |
91 | This is not intended to be a comprehensive list of all outstanding bugs.
92 |
93 | * [Issue 360]: `thread_local` variables with non-trivial destructors will cause
94 | segfaults if the containing library is `dlclose`ed. This was fixed in API 28,
95 | but code running on devices older than API 28 will need a workaround. The
96 | simplest fix is to **stop calling `dlclose`**. If you absolutely must continue
97 | calling `dlclose`, see the following table:
98 |
99 | | | Pre-API 23 | APIs 23-27 | API 28+ |
100 | | ----------------- | -------------------- | ------------- | ------- |
101 | | No workarounds | Works for static STL | Broken | Works |
102 | | `-Wl,-z,nodelete` | Works for static STL | Works | Works |
103 | | No `dlclose` | Works | Works | Works |
104 |
105 | If your code must run on devices older than M (API 23) and you cannot use the
106 | static STL (common), **the only fix is to not call `dlclose`**, or to stop
107 | using `thread_local` variables with non-trivial destructors.
108 |
109 | If your code does not need to run on devices older than API 23 you can link
110 | with `-Wl,-z,nodelete`, which instructs the linker to ignore `dlclose` for
111 | that library. You can backport this behavior by not calling `dlclose`.
112 |
113 | The fix in API 28 is the standardized inhibition of `dlclose`, so you can
114 | backport the fix to older versions by not calling `dlclose`.
115 |
116 | * [Issue 988]: Exception handling when using ASan via wrap.sh can crash. To
117 | workaround this issue when using libc++_shared, ensure that your application's
118 | libc++_shared.so is in `LD_PRELOAD` in your `wrap.sh` as in the following
119 | example:
120 |
121 | ```bash
122 | #!/system/bin/sh
123 | HERE="$(cd "$(dirname "$0")" && pwd)"
124 | export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
125 | ASAN_LIB=$(ls $HERE/libclang_rt.asan-*-android.so)
126 | if [ -f "$HERE/libc++_shared.so" ]; then
127 | # Workaround for https://github.com/android/ndk/issues/988.
128 | export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
129 | else
130 | export LD_PRELOAD="$ASAN_LIB"
131 | fi
132 | "$@"
133 | ```
134 |
135 | There is no known workaround for libc++_static.
136 |
137 | Note that because this is a platform bug rather than an NDK bug this cannot be
138 | fixed with an NDK update. This workaround will be necessary for code running
139 | on devices that do not contain the fix, and the bug has not been fixed even in
140 | the latest release of Android.
141 |
142 | [Issue 360]: https://github.com/android/ndk/issues/360
143 | [Issue 988]: https://github.com/android/ndk/issues/988
144 |
--------------------------------------------------------------------------------
/docs/changelogs/Changelog-r27.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | Report issues to [GitHub].
4 |
5 | For Android Studio issues, go to https://b.android.com and file a bug using the
6 | Android Studio component, not the NDK component.
7 |
8 | If you're a build system maintainer that needs to use the tools in the NDK
9 | directly, see the [build system maintainers guide].
10 |
11 | [GitHub]: https://github.com/android/ndk/issues
12 | [build system maintainers guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
13 |
14 | ## Announcements
15 |
16 | * Android V will allow OEMs to ship arm64-v8a devices with 16KiB page sizes.
17 | Devices that use this configuration will not be able to run existing apps that
18 | use native code. To be compatible with these devices, applications will need
19 | to rebuild all their native code to be 16KiB aligned, and rewrite any code
20 | which assumes a specific page size. ndk-build and CMake have options to enable
21 | this mode (see note about `APP_SUPPORT_FLEXIBLE_PAGE_SIZES` and
22 | `ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES` below). A future version of the NDK will
23 | enable this mode by default. If you're using or maintaining a third-party
24 | build system, consult the [build system maintainers guide] for instructions.
25 |
26 | See [Support 16 KB page sizes] for more information.
27 |
28 | [Support 16 KB page sizes]: https://developer.android.com/guide/practices/page-sizes
29 |
30 | ## r27b
31 |
32 | * Updated LLVM to clang-r522817b. See `clang_source_info.md` in the toolchain
33 | directory for version information.
34 | * [Issue 2040]: Fixed miscompile with indirect gotos.
35 | * [Issue 2054]: Fixed crash in x86 fp16 instruction selection.
36 | * [Issue 2059]: Fixed infinite loop in aarch64 vector instruction selection.
37 | * [Issue 2032]: Fixed compatibility issues with projects that used a very old
38 | `cmake_minimum_required` version ("Policy CMP0057 is not set: Support new
39 | IN_LIST if() operator").
40 | * [Issue 2039]: Fixed `LOCAL_STRIP_MODE` not being reset by
41 | `include $(CLEAR_VARS)`.
42 | * [Issue 2049]: Restored metadata used by CMake in non-toolchain-file use cases
43 | that used `CMAKE_SYSTEM_PROCESSOR` instead of `CMAKE_ANDROID_ARCH_ABI`. If you
44 | ran into this problem, you should switch to using `CMAKE_ANDROID_ARCH_ABI`
45 | because that's what [CMake's docs] say to use. Better still, use the NDK's
46 | [toolchain file].
47 |
48 | [Issue 2032]: https://github.com/android/ndk/issues/2032
49 | [Issue 2039]: https://github.com/android/ndk/issues/2039
50 | [Issue 2040]: https://github.com/android/ndk/issues/2040
51 | [Issue 2049]: https://github.com/android/ndk/issues/2049
52 | [Issue 2054]: https://github.com/android/ndk/issues/2054
53 | [Issue 2059]: https://github.com/android/ndk/issues/2059
54 | [CMake's docs]: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android-with-the-ndk
55 | [toolchain file]: https://developer.android.com/ndk/guides/cmake
56 |
57 | ## Changes
58 |
59 | * Updated LLVM to clang-r522817. See `clang_source_info.md` in the toolchain
60 | directory for version information.
61 | * [Issue 1728]: Clang now emits an error for invalid Android target versions.
62 | * [Issue 1853]: `clang-scan-deps` is now included.
63 | * [Issue 1911]: Fixed inconsistent `std::regex_replace` results.
64 | * [Issue 1947]: Improved support for AArch64 function multi-versioning in clang.
65 | * [Issue 1963]: Fixed undefined behavior in `std::unexpected::has_value()`.
66 | * [Issue 1988]: Added aarch64 support for `preserve_all` calling convention.
67 | * [Issue 2007]: Fixed crash in class template argument deduction caused by
68 | self-referential friend declaration.
69 | * [Issue 2010]: Removed superfluous libraries to reduce disk use.
70 | * [Issue 2012]: Fixed front end crash when using concepts and modules.
71 | * [Issue 2013]: Fixed false positive ODR violation in global module fragments.
72 | * [Issue 2023]: Fixed Clang crashes related to lambda captures in unevaluated
73 | contexts.
74 | * [Issue 2024]: Removed invalid `__attribute__((__const__))` from `gettid`.
75 | * A RISC-V sysroot (AKA riscv64, or rv64) has been added. It is **not**
76 | supported. It is present to aid bringup for OS vendors, but it's not yet a
77 | supported Android ABI. It will not be built by default.
78 | * [Issue 1856]: Target-prefixed cmd wrappers for clang should now behave
79 | appropriately when the first argument includes quotes. **You probably do not
80 | need to use those wrappers.** In most cases where you would use
81 | `aarch64-linux-android21-clang`, you can instead use `clang -target
82 | aarch64-linux-android21`, e.g. `CC="clang -target aarch64-linux-android21"
83 | ./configure`. The wrappers are only needed when working with systems that do
84 | not properly handle a `CC` that includes arguments.
85 | * [Issue 1898]: ndk-stack now tolerates 0x prefixed addresses.
86 | * [Issue 1921]: `ANDROID_USE_LEGACY_TOOLCHAIN_FILE` value is now preserved
87 | during try-compile steps when `ON`.
88 | * [Issue 1974]: Unintentionally shipped Vulkan headers have been removed from
89 | `sources/third_party/vulkan`. The standard Vulkan headers are included in the
90 | Android sysroot, which Clang will find automatically.
91 | * [Issue 1993]: ndk-stack now tolerates invalid UTF-8 characters in the trace.
92 | * [Issue 1994]: Fixed ndk-gdb/ndk-lldb to use the correct path for
93 | make and other tools.
94 | * Added `APP_SUPPORT_FLEXIBLE_PAGE_SIZES` for ndk-build and
95 | `ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES` for CMake. Set to
96 | `APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true` in your `Application.mk` or pass
97 | `-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON` to CMake (via
98 | `android.defaultConfig.externalNativeBuild.cmake.arguments` if you're using
99 | the Android Gradle Plugin) to build your code to be compatible with devices
100 | that use a 16KiB page size. Third-party build system users and maintainers
101 | should consult the [build system maintainers guide].
102 | * Symlinks are now properly preserved in the macOS App Bundle. The NDK installed
103 | via that method is now the same size as the one installed via the SDK manager.
104 | * The unsupported libclang, libclang-cpp, libLLVM, and libLTO libraries were
105 | removed to save space.
106 |
107 | [Issue 1728]: https://github.com/android/ndk/issues/1728
108 | [Issue 1853]: https://github.com/android/ndk/issues/1853
109 | [Issue 1856]: https://github.com/android/ndk/issues/1856
110 | [Issue 1898]: https://github.com/android/ndk/issues/1898
111 | [Issue 1911]: https://github.com/android/ndk/issues/1911
112 | [Issue 1921]: https://github.com/android/ndk/issues/1921
113 | [Issue 1947]: https://github.com/android/ndk/issues/1947
114 | [Issue 1963]: https://github.com/android/ndk/issues/1963
115 | [Issue 1974]: https://github.com/android/ndk/issues/1974
116 | [Issue 1988]: https://github.com/android/ndk/issues/1988
117 | [Issue 1993]: https://github.com/android/ndk/issues/1993
118 | [Issue 1994]: https://github.com/android/ndk/issues/1994
119 | [Issue 2007]: https://github.com/android/ndk/issues/2007
120 | [Issue 2010]: https://github.com/android/ndk/issues/2010
121 | [Issue 2012]: https://github.com/android/ndk/issues/2012
122 | [Issue 2013]: https://github.com/android/ndk/issues/2013
123 | [Issue 2023]: https://github.com/android/ndk/issues/2023
124 | [Issue 2024]: https://github.com/android/ndk/issues/2024
125 |
--------------------------------------------------------------------------------
/docs/repo.md:
--------------------------------------------------------------------------------
1 | # Using repo and Gerrit for the NDK
2 |
3 | Android uses [repo](https://source.android.com/setup/develop#repo) for managing
4 | the collections of individual git repositories needed by each "tree". See that
5 | page for more information, including install instructions. You'll need to
6 | install repo before you can work with Android repositories.
7 |
8 | ## Downloading the source
9 |
10 | AOSP's [Downloading the source] explains how to initialize a new tree (similar
11 | to `git clone`, but for a whole repo tree). For the NDK the main difference is
12 | that you need to specify the master-ndk branch by adding `-b master-ndk`. See
13 | [Building.md](Building.md) for more specific instructions.
14 |
15 | Warning: Unlike `git clone`, `repo init` will **not** check out the source into
16 | a new directory. If you run `repo init && repo sync` in your home directory you
17 | will have a lot to clean up. If you run `repo init` in a tree that already has a
18 | different repo tree in it, you'll reinitialize that tree with a different branch
19 | and the next sync may delete existing projects.
20 |
21 | `repo init` only prepares the tree, you'll still need to run `repo sync` to
22 | fetch the source.
23 |
24 | [Downloading the source]: https://source.android.com/setup/build/downloading
25 |
26 | ## Pulling updates
27 |
28 | The `repo` equivalent of `git pull` is `repo sync`. It's recommended that you
29 | run `repo sync -c -j $THREADS`. `-c` ensures that only the branches that are
30 | needed are fetched to avoid consuming too much disk space, and `-j $THREADS`
31 | allows repo to use multiple threads when updating.
32 |
33 | ## Making changes
34 |
35 | `repo` trees place git projects in a detached HEAD state by default. To create a
36 | local branch that can be sent for review, use `repo start $BRANCH_NAME .`. This
37 | is similar to `git checkout -b` or `git switch -c`, but will configure the new
38 | branch so that it can be uploaded for review.
39 |
40 | Any time you start new work, use `repo start $BRANCH_NAME .`. Each local branch
41 | is its own review chain, so you'll want separate branches for distinct changes.
42 |
43 | ## Committing changes
44 |
45 | When you're ready to upload your changes, commit them to your local branch.
46 | Gerrit will create one review per commit and will associate commits that are in
47 | the same branch together in a series. If you made many commits while working on
48 | the change, squash them (`repo rebase -i --autosquash .` will start an
49 | interactive rebase that you can use to re-order and combine commits) so that
50 | each commit is complete but minimal. Splitting large changes into multiple
51 | commits improves reviewability, but each commit should be able to build and pass
52 | tests on its own so it can be submitted individually.
53 |
54 | In most cases you'll only need one commit in a branch.
55 |
56 | ## Uploading changes for review
57 |
58 | To get changes reviewed, run `repo upload --cbr .`. This will upload the commits
59 | in the current branch and directory. To upload changes in other directories,
60 | pass those paths instead of `.`. Multiple paths can be given to upload multiple
61 | projects with the same command.`--cbr` is "current branch". Without `--cbr` an
62 | interactive mode will open in your editor that you can use to upload branches
63 | other than the one that is currently checked out.
64 |
65 | You can also add reviewers when uploading your changes with the
66 | `--re=$USER1,$USER2,...` argument. If your reviewers are Googlers, Gerrit can
67 | *usually* work out that `name` means `name@google.com`. In other cases you'll
68 | need to spell out the full email address of the reviewer.
69 |
70 | Once the change is uploaded, you can open it in Gerrit and enable autosubmit if
71 | you want the change to be submitted once it has been reviewed and passed
72 | presubmit testing. Don't worry, if anyone has review comments those will prevent
73 | the change from being submitted before you can see them.
74 |
75 | To minimize the amount of time you spend waiting on machines, it's best to vote
76 | Presubmit Ready+1 on your change when you upload it to get treehugger running
77 | ASAP. By default treehugger won't start testing a change until it has either
78 | been +2'd or has autosubmit set.
79 |
80 | If you have changes that span multiple git projects that need to be submitted
81 | together (are mutually dependent), give them the same topic name in Gerrit. If
82 | you used the same branch name when running `repo start` in each project, you can
83 | pass `-t` to `repo upload` to automatically assign the branch name as the topic
84 | name in Gerrit.
85 |
86 | ## Responding to review comments
87 |
88 | To update your commit to address review comments, make the change and amend the
89 | commit. If you have a stack of commits and need to amend something other than
90 | the top commit, you can use the `--fixup` argument to `git commit` and then
91 | rebase with `--autosquash`, or use the `edit` option on a commit after starting
92 | an interactive rebase (`repo rebase -i --autosquash .`).
93 |
94 | After amending your changes, run `repo upload` again as you did before. This
95 | will create a new "patch set" (PS) for the existing review in Gerrit. This is a
96 | new "version" of the commit. You do not need to specify reviewers again when
97 | uploading new patch sets.
98 |
99 | ## Submitting
100 |
101 | Once you have approval (Code Review +2) and either a +1 or a +2 from someone in
102 | the OWNERS file (or are in the OWNERS file yourself), all review comments have
103 | been addressed and marked as "Done", and presubmit (AKA "treehugger") has
104 | responded with Presubmit Verified +1, your change can be submitted. If you
105 | enabled autosubmit this will happen automatically. Otherwise use the "Submit"
106 | button in the UI.
107 |
108 | ## Cheat sheet for GitHub users
109 |
110 | The repo/Gerrit process has some differences compared to the GitHub Pull Request
111 | workflow. If you're familiar with using pull requests you should read everything
112 | above for the details, but here's a quick cheat sheet mapping similar processes:
113 |
114 | GitHub | Gerrit
115 | --- | ---
116 | `git clone $X` | `mkdir $X && cd $X && repo init $X && repo sync`
117 | `git pull` | `repo sync`
118 | `git checkout -b`/`git switch -c` | `repo start .`
119 | `git push` and other pull request steps | `repo upload`
120 |
--------------------------------------------------------------------------------
/docs/user/common_problems.md:
--------------------------------------------------------------------------------
1 | Moved to https://developer.android.com/ndk/guides/common-problems
2 |
--------------------------------------------------------------------------------
/docs/user/middleware_vendors.md:
--------------------------------------------------------------------------------
1 | Moved to https://developer.android.com/ndk/guides/middleware-vendors
2 |
--------------------------------------------------------------------------------
/patches/cmake/Android-Clang.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/cmake/share/cmake-3.22/Modules/Platform/Android-Clang.cmake 2021-11-18 23:51:22.000000000 +0800
2 | +++ b/cmake/share/cmake-3.22/Modules/Platform/Android-Clang.cmake 2021-12-05 10:55:02.941248123 +0800
3 | @@ -46,7 +46,9 @@
4 | if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
5 | macro(__android_compiler_clang lang)
6 | endmacro()
7 | - return()
8 | + if(NOT CMAKE_ANDROID_NDK)
9 | + return()
10 | + endif()
11 | endif()
12 |
13 | include(Platform/Android-Common)
14 |
--------------------------------------------------------------------------------
/patches/cmake/Android-Determine.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/cmake/share/cmake-3.22/Modules/Platform/Android-Determine.cmake 2021-11-18 23:51:22.000000000 +0800
2 | +++ b/cmake/share/cmake-3.22/Modules/Platform/Android-Determine.cmake 2021-12-05 10:56:02.534731135 +0800
3 | @@ -26,7 +26,7 @@
4 |
5 | # Natively compiling on an Android host doesn't use the NDK cross-compilation
6 | # tools.
7 | -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
8 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_ANDROID_NDK)
9 | return()
10 | endif()
11 |
12 | @@ -268,7 +268,9 @@
13 |
14 | if(CMAKE_ANDROID_NDK)
15 | # Identify the host platform.
16 | - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
17 | + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
18 | + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "linux-aarch64")
19 | + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
20 | if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "64")
21 | set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "darwin-x86_64")
22 | else()
23 |
--------------------------------------------------------------------------------
/patches/cmake/Android-Initialize.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/cmake/share/cmake-3.22/Modules/Platform/Android-Initialize.cmake 2021-11-18 23:51:22.000000000 +0800
2 | +++ b/cmake/share/cmake-3.22/Modules/Platform/Android-Initialize.cmake 2021-12-05 10:57:34.498031789 +0800
3 | @@ -77,7 +77,7 @@
4 |
5 | # Natively compiling on an Android host doesn't use the NDK cross-compilation
6 | # tools.
7 | -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
8 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_ANDROID_NDK)
9 | return()
10 | endif()
11 |
12 |
--------------------------------------------------------------------------------
/patches/cmake/Android.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/cmake/share/cmake-3.22/Modules/Platform/Android.cmake 2021-11-18 23:51:22.000000000 +0800
2 | +++ b/cmake/share/cmake-3.22/Modules/Platform/Android.cmake 2021-12-05 10:55:49.174568422 +0800
3 | @@ -9,7 +9,7 @@
4 | set(ANDROID 1)
5 |
6 | # Natively compiling on an Android host doesn't need these flags to be reset.
7 | -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
8 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_ANDROID_NDK)
9 | return()
10 | endif()
11 |
12 |
--------------------------------------------------------------------------------
/patches/cmake/Determine-Compiler.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/cmake/share/cmake-3.22/Modules/Platform/Android/Determine-Compiler.cmake 2021-11-18 23:51:22.000000000 +0800
2 | +++ b/cmake/share/cmake-3.22/Modules/Platform/Android/Determine-Compiler.cmake 2021-12-05 10:58:18.118071997 +0800
3 | @@ -46,7 +46,10 @@
4 | if(NOT CMAKE_CXX_COMPILER_NAMES)
5 | set(CMAKE_CXX_COMPILER_NAMES c++)
6 | endif()
7 | - return()
8 | + set(_ANDROID_HOST_EXT "")
9 | + if(NOT CMAKE_ANDROID_NDK)
10 | + return()
11 | + endif()
12 | else()
13 | message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.")
14 | endif()
15 |
--------------------------------------------------------------------------------
/patches/crypt.h:
--------------------------------------------------------------------------------
1 | #ifndef CRYPT_H_INCLUDED
2 | #define CRYPT_H_INCLUDED
3 |
4 | #include
5 |
6 | __BEGIN_DECLS
7 |
8 | char* crypt(const char* key, const char* salt);
9 |
10 | __END_DECLS
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/patches/llvm_android/base_builders.py.patch:
--------------------------------------------------------------------------------
1 | --- a/toolchain/llvm_android/base_builders.py 2024-09-21 18:26:34.714000000 +0800
2 | +++ b/toolchain/llvm_android/base_builders.py 2024-09-25 11:22:38.106196558 +0800
3 | @@ -193,7 +193,7 @@
4 | @property
5 | def cflags(self) -> List[str]:
6 | """Additional cflags to use."""
7 | - return []
8 | + return ['--target=aarch64-linux-android28']
9 |
10 | @property
11 | def cxxflags(self) -> List[str]:
12 | @@ -719,7 +719,15 @@
13 | defines['LLVM_ENABLE_PROJECTS'] = ';'.join(sorted(self.llvm_projects))
14 | defines['LLVM_ENABLE_RUNTIMES'] = ';'.join(sorted(self.llvm_runtime_projects))
15 |
16 | - defines['LLVM_TARGETS_TO_BUILD'] = ';'.join(sorted(self.llvm_targets))
17 | + defines['LLVM_TARGETS_TO_BUILD']= 'all'
18 | + defines['DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD']='ARC;CSKY;M68k;VE'
19 | + defines['DLLVM_ENABLE_FFI']='ON'
20 | + defines['LLVM_ENABLE_PIC'] = 'ON'
21 | + defines['CMAKE_BUILD_WITH_INSTALL_RPATH'] = 'ON'
22 | + defines['CMAKE_POLICY_DEFAULT_CMP0116'] = 'OLD'
23 | + defines['LLVM_TARGET_ARCH'] = 'AArch64'
24 | + defines['LLVM_HOST_TRIPLE'] = 'aarch64-unknown-linux-android28'
25 | +
26 | if self._config.target_os.is_darwin or self._config.target_os.is_linux:
27 | defines['LLVM_BUILD_LLVM_DYLIB'] = 'ON'
28 | elif isinstance(self._config, configs.MSVCConfig):
29 | @@ -785,7 +793,7 @@
30 |
31 | # Add libc++abi to libc++.{a,dylib} for consistency with Linux.
32 | defines['LIBCXX_ENABLE_STATIC_ABI_LIBRARY'] = 'ON'
33 | -
34 | +
35 | if self._config.target_os.is_linux:
36 | runtime_configs: List[configs.Config] = []
37 | if self.build_cross_runtimes:
38 |
--------------------------------------------------------------------------------
/patches/llvm_android/builders.py.patch:
--------------------------------------------------------------------------------
1 | --- a/toolchain/llvm_android/builders.py 2024-09-21 18:26:34.718000000 +0800
2 | +++ b/toolchain/llvm_android/builders.py 2024-09-25 11:16:26.522196699 +0800
3 | @@ -212,6 +212,7 @@
4 | def cflags(self) -> List[str]:
5 | cflags = super().cflags
6 | if self.profdata_file:
7 | + cflags.append('-Wno-android-unversioned-fallback')
8 | cflags.append('-Wno-profile-instr-out-of-date')
9 | cflags.append('-Wno-profile-instr-unprofiled')
10 | if not self.lto and self.enable_mlgo:
11 |
--------------------------------------------------------------------------------
/patches/llvm_android/configs.py.patch:
--------------------------------------------------------------------------------
1 | --- a/toolchain/llvm_android/configs.py 2024-09-21 18:26:34.722000000 +0800
2 | +++ b/toolchain/llvm_android/configs.py 2024-09-25 11:09:11.226196866 +0800
3 | @@ -295,22 +295,22 @@
4 | """Configuration for Linux targets."""
5 |
6 | target_os: hosts.Host = hosts.Host.Linux
7 | - sysroot: Optional[Path] = (paths.GCC_ROOT / 'host' / 'x86_64-linux-glibc2.17-4.8' / 'sysroot')
8 | - gcc_root: Path = (paths.GCC_ROOT / 'host' / 'x86_64-linux-glibc2.17-4.8')
9 | - gcc_triple: str = 'x86_64-linux'
10 | - gcc_ver: str = '4.8.3'
11 | + sysroot: Optional[Path] = (paths.GCC_ROOT / 'sysroot')
12 | + gcc_root: Path = (paths.GCC_ROOT)
13 | + gcc_triple: str = 'aarch64-linux-android'
14 | + gcc_ver: str = '4.9.x'
15 | is_cross_compiling: bool = False
16 | is_musl: bool = False
17 |
18 | @property
19 | def llvm_triple(self) -> str:
20 | - return 'i386-unknown-linux-gnu' if self.is_32_bit else 'x86_64-unknown-linux-gnu'
21 | + return 'arm-unknown-linux-androideabi' if self.is_32_bit else 'aarch64-unknown-linux-android'
22 |
23 | @property
24 | def cflags(self) -> List[str]:
25 | cflags = super().cflags
26 | if self.is_32_bit and not self.is_musl:
27 | - cflags.append('-march=i686')
28 | + cflags.append('-march=armv7-a')
29 | return cflags
30 |
31 |
32 |
--------------------------------------------------------------------------------
/patches/llvm_android/paths.py.patch:
--------------------------------------------------------------------------------
1 | --- a/toolchain/llvm_android/paths.py 2024-09-21 18:26:34.858000000 +0800
2 | +++ b/toolchain/llvm_android/paths.py 2024-09-22 09:45:14.634342932 +0800
3 | @@ -70,7 +70,7 @@
4 |
5 | RISCV64_ANDROID_SYSROOT: Path = TOOLCHAIN_DIR / 'prebuilts' / 'sysroot' / 'platform' / 'riscv64-linux-android'
6 |
7 | -GCC_ROOT: Path = PREBUILTS_DIR / 'gcc' / hosts.build_host().os_tag
8 | +GCC_ROOT :Path = CLANG_PREBUILT_DIR
9 | GO_ROOT: Path = PREBUILTS_DIR / 'go' / hosts.build_host().os_tag
10 | MINGW_ROOT: Path = PREBUILTS_DIR / 'gcc' / 'linux-x86' / 'host' / 'x86_64-w64-mingw32-4.8' / 'x86_64-w64-mingw32'
11 |
12 |
--------------------------------------------------------------------------------
/patches/llvm_project/Editline.h.patch:
--------------------------------------------------------------------------------
1 | --- a/llvm-project/lldb/include/lldb/Host/Editline.h 2021-11-30 13:34:49.653844615 +0800
2 | +++ b/llvm-project/lldb/include/lldb/Host/Editline.h 2021-12-05 11:24:17.261484415 +0800
3 | @@ -43,7 +43,7 @@
4 |
5 | #if defined(_WIN32)
6 | #include "lldb/Host/windows/editlinewin.h"
7 | -#elif !defined(__ANDROID__)
8 | +#else
9 | #include
10 | #endif
11 |
12 |
--------------------------------------------------------------------------------
/patches/llvm_project/IOHandlerCursesGUI.cpp.patch:
--------------------------------------------------------------------------------
1 | --- a/llvm-project/lldb/source/Core/IOHandlerCursesGUI.cpp 2021-11-30 13:34:50.967178079 +0800
2 | +++ b/llvm-project/lldb/source/Core/IOHandlerCursesGUI.cpp 2021-12-05 11:20:25.151196833 +0800
3 | @@ -9,6 +9,11 @@
4 | #include "lldb/Core/IOHandlerCursesGUI.h"
5 | #include "lldb/Host/Config.h"
6 |
7 | +#ifdef CURSES_HAVE_NCURSES_CURSES_H
8 | +#undef CURSES_HAVE_NCURSES_CURSES_H
9 | +#endif
10 | +#define CURSES_HAVE_NCURSES_CURSES_H 1
11 | +
12 | #if LLDB_ENABLE_CURSES
13 | #if CURSES_HAVE_NCURSES_CURSES_H
14 | #include
15 |
--------------------------------------------------------------------------------
/patches/llvm_project/vis.c.patch:
--------------------------------------------------------------------------------
1 | --- a/external/libedit/src/vis.c 2020-11-28 16:17:05.333521910 +0800
2 | +++ b/external/libedit/src/vis.c 2021-12-05 11:18:29.889675857 +0800
3 | @@ -85,6 +85,9 @@
4 | #include
5 | #include
6 |
7 | +#ifndef NBBY
8 | +#define NBBY 8
9 | +#endif
10 |
11 | /*
12 | * The reason for going through the trouble to deal with character encodings
13 |
--------------------------------------------------------------------------------
/patches/ndk/android-legacy.toolchain.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/build/cmake/android-legacy.toolchain.cmakeandroid-legacy.toolchain.cmake 2024-09-25 11:32:13.000000000 +0800
2 | +++ b/build/cmake/android-legacy.toolchain.cmake 2024-09-24 18:33:57.626219644 +0800
3 | @@ -371,7 +371,7 @@
4 | message(FATAL_ERROR "Invalid STL: ${ANDROID_STL}.")
5 | endif()
6 |
7 | -if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
8 | +if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux|Android)
9 | set(ANDROID_HOST_TAG linux-x86_64)
10 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
11 | set(ANDROID_HOST_TAG darwin-x86_64)
12 |
--------------------------------------------------------------------------------
/patches/ndk/android.toolchain.cmake.patch:
--------------------------------------------------------------------------------
1 | --- a/build/cmake/android.toolchain.cmake 2024-09-25 11:32:13.000000000 +0800
2 | +++ b/build/cmake/android.toolchain.cmake 2024-09-24 18:34:08.814219640 +0800
3 | @@ -272,7 +272,7 @@
4 | # Exports compatible variables defined in exports.cmake.
5 | set(_ANDROID_EXPORT_COMPATIBILITY_VARIABLES TRUE)
6 |
7 | -if(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
8 | +if(CMAKE_HOST_SYSTEM_NAME MATCHES Linux|Android)
9 | set(ANDROID_HOST_TAG linux-x86_64)
10 | elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
11 | set(ANDROID_HOST_TAG darwin-x86_64)
12 |
--------------------------------------------------------------------------------
/patches/ndk/autoconf.py.patch:
--------------------------------------------------------------------------------
1 | --- a/ndk/autoconf.pyautoconf.py 2024-09-24 12:58:53.504000000 +0800
2 | +++ b/ndk/autoconf.py 2024-09-25 11:27:19.786196450 +0800
3 | @@ -30,7 +30,7 @@
4 |
5 | HOST_TRIPLE_MAP = {
6 | Host.Darwin: "x86_64-apple-darwin",
7 | - Host.Linux: "aarch64-unknown-linux-android",
8 | + Host.Linux: "x86_64-linux-gnu",
9 | Host.Windows64: "x86_64-w64-mingw32",
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/patches/ndk/checkbuild.py.patch:
--------------------------------------------------------------------------------
1 | --- a/ndk/checkbuild.py 2024-09-25 11:32:13.000000000 +0800
2 | +++ b/ndk/checkbuild.py 2024-09-25 11:37:49.338196210 +0800
3 | @@ -676,6 +676,7 @@
4 | # Don't enable RE2 testing because it's long and not useful to us.
5 | "RE2_BUILD_TESTING": "OFF",
6 | "SPIRV-Headers_SOURCE_DIR": str(spirv_headers_dir),
7 | + "SHADERC_SKIP_TESTS": "ON"
8 | }
9 | return defines
10 |
11 | @@ -693,7 +694,7 @@
12 | if self.host == Host.Linux:
13 | # Our libc++.so.1 re-exports libc++abi, and it will be installed in
14 | # the same directory as the executables.
15 | - ldflags += ["-Wl,-rpath,\\$ORIGIN"]
16 | + ldflags += ["-Wl,-rpath,\\$ORIGIN", "-static-libstdc++"]
17 | if self.host == Host.Windows64:
18 | # TODO: The shaderc CMake files already pass these options for
19 | # gcc+mingw but not for clang+mingw. See
20 | @@ -758,7 +759,7 @@
21 |
22 |
23 | @register
24 | -class Make(ndk.builds.CMakeModule):
25 | +class Make(ndk.builds.AutoconfModule):
26 | name = "make"
27 | install_path = Path("prebuilt/{host}")
28 | notice_group = ndk.builds.NoticeGroup.TOOLCHAIN
29 |
--------------------------------------------------------------------------------
/patches/ndk/ndk_bin_common.sh.patch:
--------------------------------------------------------------------------------
1 | --- a/build/tools/ndk_bin_common.sh 2024-09-25 11:32:13.000000000 +0800
2 | +++ b/build/tools/ndk_bin_common.sh 2024-09-24 12:01:04.736272881 +0800
3 | @@ -27,6 +27,7 @@
4 |
5 | HOST_ARCH=$(uname -m)
6 | case $HOST_ARCH in
7 | + aarch64) HOST_ARCH=aarch64;;
8 | arm64) HOST_ARCH=arm64;;
9 | i?86) HOST_ARCH=x86;;
10 | x86_64|amd64) HOST_ARCH=x86_64;;
11 |
--------------------------------------------------------------------------------
/patches/ndk/toolchains.py.patch:
--------------------------------------------------------------------------------
1 | --- a/ndk/toolchains.py 2024-09-23 19:20:36.948000000 +0800
2 | +++ b/ndk/toolchains.py 2024-09-23 23:09:51.660290533 +0800
3 | @@ -26,7 +26,7 @@
4 |
5 | HOST_TRIPLE_MAP = {
6 | Host.Darwin: "x86_64-apple-darwin",
7 | - Host.Linux: "x86_64-linux-gnu",
8 | + Host.Linux: "aarch64-linux-android28",
9 | Host.Windows64: "x86_64-w64-mingw32",
10 | }
11 |
12 | @@ -224,7 +224,7 @@
13 | if self.target == Host.Linux:
14 | return (
15 | ndk.paths.ANDROID_DIR
16 | - / "prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8"
17 | + / "prebuilts/clang/host/linux-x86" / CLANG_VERSION
18 | )
19 | return (
20 | ndk.paths.ANDROID_DIR
21 | @@ -243,7 +243,7 @@
22 | """Returns the GCC triple for the host toolchain."""
23 | return {
24 | Host.Darwin: "x86_64-apple-darwin11",
25 | - Host.Linux: "x86_64-linux",
26 | + Host.Linux: "aarch64-linux-android",
27 | Host.Windows64: "x86_64-w64-mingw32",
28 | }[self.target]
29 |
30 | @@ -317,6 +317,7 @@
31 | flags = [
32 | f"--target={host_triple}",
33 | ]
34 | + flags.append('-fcolor-diagnostics')
35 |
36 | if self.target.is_windows:
37 | flags.append("-I" + str(self.path_for_host(self.target) / "include/c++/v1"))
38 |
--------------------------------------------------------------------------------