Add mdformat pre-commit, and format all markdown. (#921)

This commit is contained in:
James Farrell
2022-12-13 13:55:06 -06:00
committed by GitHub
parent 50f5fc5f80
commit e73d5df22b
40 changed files with 1572 additions and 1265 deletions

View File

@@ -11,3 +11,10 @@ repos:
hooks:
- id: check-xml
- id: check-yaml
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
args: ["--wrap", "80"]
additional_dependencies:
- mdformat-gfm

View File

@@ -2,18 +2,18 @@
## Contributor License Agreements
We'd love to accept your sample apps and patches! Before we can take them, we
We'd love to accept your sample apps and patches! Before we can take them, we
have to jump a couple of legal hurdles.
Please fill out either the individual or corporate Contributor License Agreement
(CLA).
* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual CLA]
(http://code.google.com/legal/individual-cla-v1.0.html).
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA]
(http://code.google.com/legal/corporate-cla-v1.0.html).
- If you are an individual writing original source code and you're sure you own
the intellectual property, then you'll need to sign an
[individual CLA](http://code.google.com/legal/individual-cla-v1.0.html).
- If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a
[corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html).
Follow either of the two links above to access the appropriate CLA and
instructions for how to sign and return it. Once we receive it, we'll be able to
@@ -24,9 +24,9 @@ accept your pull requests.
1. Sign a Contributor License Agreement, if you have not yet done so (see
details above).
1. Create your change to the repo in question.
* Fork the desired repo, develop and test your code changes.
* Ensure that your code is clear and comprehensible.
* Ensure that your code has an appropriate set of unit tests which all pass.
- Fork the desired repo, develop and test your code changes.
- Ensure that your code is clear and comprehensible.
- Ensure that your code has an appropriate set of unit tests which all pass.
1. Submit a pull request.
1. The repo owner will review your request. If it is approved, the change will
be merged. If it needs additional work, the repo owner will respond with

View File

@@ -1,65 +1,80 @@
NDK Samples [![build](https://github.com/android/ndk-samples/workflows/build/badge.svg)](https://github.com/android/ndk-samples/actions)
===========
# NDK Samples [![build](https://github.com/android/ndk-samples/workflows/build/badge.svg)](https://github.com/android/ndk-samples/actions)
This repository contains [Android NDK][0] samples with Android Studio [C++ integration](https://www.youtube.com/watch?v=f7ihSQ44WO0&feature=youtu.be).
This repository contains [Android NDK][0] samples with Android Studio
[C++ integration](https://www.youtube.com/watch?v=f7ihSQ44WO0&feature=youtu.be).
These samples use the new [CMake Android plugin](https://developer.android.com/studio/projects/add-native-code.html) with C++ support.
These samples use the new
[CMake Android plugin](https://developer.android.com/studio/projects/add-native-code.html)
with C++ support.
Samples could also be built with other build systems:
- for ndk-build with Android Studio, refer to directory [other-builds/ndkbuild](https://github.com/googlesamples/android-ndk/tree/master/other-builds/ndkbuild)
- for gradle-experimental plugin, refer to directory other-builds/experimental. Note that gradle-experimental does not work with unified headers yet: use NDK version up to r15 and Android Studio up to version 2.3. When starting new project, please use CMake or ndk-build plugin.
Additional Android Studio samples:
- for ndk-build with Android Studio, refer to directory
[other-builds/ndkbuild](https://github.com/googlesamples/android-ndk/tree/master/other-builds/ndkbuild)
- for gradle-experimental plugin, refer to directory other-builds/experimental.
Note that gradle-experimental does not work with unified headers yet: use NDK
version up to r15 and Android Studio up to version 2.3. When starting new
project, please use CMake or ndk-build plugin.
Additional Android Studio samples:
- [Google Play Game Samples with Android Studio](https://github.com/playgameservices/cpp-android-basic-samples)
- [Google Android Vulkan Tutorials](https://github.com/googlesamples/android-vulkan-tutorials)
- [Android Vulkan API Basic Samples](https://github.com/googlesamples/vulkan-basic-samples)
- [Android High Performance Audio](https://github.com/googlesamples/android-audio-high-performance)
- [Android High Performance Audio](https://github.com/googlesamples/android-audio-high-performance)
Documentation
- [Add Native Code to Your Project](https://developer.android.com/studio/projects/add-native-code.html)
- [Configure NDK for Android Studio/Gradle Plugin](https://github.com/android/ndk-samples/wiki/Configure-NDK-Path)
- [CMake for NDK](https://developer.android.com/ndk/guides/cmake.html)
Known Issues
- For Studio related issues, refer to [Android Studio known issues](http://tools.android.com/knownissues) page
- For Studio related issues, refer to
[Android Studio known issues](http://tools.android.com/knownissues) page
- For NDK issues, refer to [ndk issues](https://github.com/android/ndk/issues)
For samples using `Android.mk` build system with `ndk-build` see the [android-mk](https://github.com/googlesamples/android-ndk/tree/android-mk) branch.
For samples using `Android.mk` build system with `ndk-build` see the
[android-mk](https://github.com/googlesamples/android-ndk/tree/android-mk)
branch.
Build Steps
----------
- With Android Studio: "Open An Existing Android Studio Project" or "File" > "Open", then navigate to & select project's build.gradle file.
- On Command Line: set up ANDROID_HOME and ANDROID_NDK_HOME to your SDK and NDK path, cd to individual sample dir, and do "gradlew assembleDebug"
## Build Steps
Support
-------
- With Android Studio: "Open An Existing Android Studio Project" or "File" >
"Open", then navigate to & select project's build.gradle file.
- On Command Line: set up ANDROID_HOME and ANDROID_NDK_HOME to your SDK and NDK
path, cd to individual sample dir, and do "gradlew assembleDebug"
## Support
For any issues you found in these samples, please
- submit patches with pull requests, see [CONTRIBUTING.md](CONTRIBUTING.md) for more details, or
- submit patches with pull requests, see [CONTRIBUTING.md](CONTRIBUTING.md) for
more details, or
- [create bugs](https://github.com/googlesamples/android-ndk/issues/new) here.
For Android NDK generic questions, please ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/android), Android teams are periodically monitoring questions there.
For Android NDK generic questions, please ask on
[Stack Overflow](https://stackoverflow.com/questions/tagged/android), Android
teams are periodically monitoring questions there.
License
-------
## License
Copyright 2018 The Android Open Source Project, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
[LICENSE](LICENSE)

View File

@@ -1,11 +1,8 @@
Android Studio/Gradle DSL References
| Name |Function | Type | Options | Default |
|---------------|-----------|:-------------:|----------|---------|
| debuggable | Debugging Java code | bool | true / false ||
| ndk.debuggable| Debugging JNI code | bool | true / false ||
Notation:
     dot(".") notation is same as closure ("{}") notation
Android Studio/Gradle DSL References
| Name | Function | Type | Options | Default |
| -------------- | ------------------- | :--: | ------------ | ------- |
| debuggable | Debugging Java code | bool | true / false | |
| ndk.debuggable | Debugging JNI code | bool | true / false | |
Notation: dot(".") notation is same as closure ("{}") notation

View File

@@ -1,93 +1,137 @@
Audio-Echo
==========
The sample demos how to use OpenSL ES to create a player and recorder in Android Fast Audio Path, and connect them to loopback audio. On most android devices, there is a optimized audio path that is tuned up for low latency purpose. The sample creates player/recorder to work in this highly optimized audio path(sometimes called native audio path, [low latency path](http://stackoverflow.com/questions/14842803/low-latency-audio-playback-on-android?rq=1), or fast audio path). The application is validated against the following configurations:
* Android L AndroidOne
* Android M Nexus 5, Nexus 9
# Audio-Echo
This sample uses the new Android Studio with CMake support, and shows how to use shared stl lib with android studio version 2.2.0, see CMakeLists.txt for details
The sample demos how to use OpenSL ES to create a player and recorder in Android
Fast Audio Path, and connect them to loopback audio. On most android devices,
there is a optimized audio path that is tuned up for low latency purpose. The
sample creates player/recorder to work in this highly optimized audio
path(sometimes called native audio path,
[low latency path](http://stackoverflow.com/questions/14842803/low-latency-audio-playback-on-android?rq=1),
or fast audio path). The application is validated against the following
configurations:
***Note that OpenSL ES is [deprecated from Android 11](https://developer.android.com/preview/features#deprecate-opensl), developers are recommended to use [Oboe](https://github.com/google/oboe) library instead.***
- Android L AndroidOne
- Android M Nexus 5, Nexus 9
This sample uses the new Android Studio with CMake support, and shows how to use
shared stl lib with android studio version 2.2.0, see CMakeLists.txt for details
***Note that OpenSL ES is
[deprecated from Android 11](https://developer.android.com/preview/features#deprecate-opensl),
developers are recommended to use [Oboe](https://github.com/google/oboe) library
instead.***
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Usage
-----
App will capture audio from android devices and playback on the same device; the playback on speaker will be captured immediately and played back...! So to verify it, it is recommended to "mute" the playback audio with a earspeaker/earphone/earbug so it does not get looped back. Some device like Nexus 9, once you plug in an external headphone/headspeaker, it stops to use onboard microphone AND speaker anymore -- in this case, you need turn on the microphone coming with your headphone. Another point, when switching between external headphone and internal one, the volume is sometimes very low/muted; recommend to increase the playback volume with volume buttons on the phone/pad after plugging external headphone.
## Usage
Low Latency Verification
------------------------
App will capture audio from android devices and playback on the same device; the
playback on speaker will be captured immediately and played back...! So to
verify it, it is recommended to "mute" the playback audio with a
earspeaker/earphone/earbug so it does not get looped back. Some device like
Nexus 9, once you plug in an external headphone/headspeaker, it stops to use
onboard microphone AND speaker anymore -- in this case, you need turn on the
microphone coming with your headphone. Another point, when switching between
external headphone and internal one, the volume is sometimes very low/muted;
recommend to increase the playback volume with volume buttons on the phone/pad
after plugging external headphone.
1. execute "adb shell dumpsys media.audio_flinger". Find a list of the running processes
## Low Latency Verification
Name Active Client Type Fmt Chn mask Session fCount S F SRate L dB R dB Server Main buf Aux Buf Flags UndFrmCnt
F 2 no 704 1 00000001 00000003 562 13248 S 1 48000 -inf -inf 000033C0 0xabab8480 0x0 0x600 0
F 6 yes 9345 3 00000001 00000001 576 128 A 1 48000 0 0 0376AA00 0xabab8480 0x0 0x400 256
1. execute "adb shell dumpsys media.audio_flinger". Find a list of the running
processes
1. execute adb shell ps | grep echo
Name Active Client Type Fmt Chn mask Session fCount S F SRate L dB R dB
Server Main buf Aux Buf Flags UndFrmCnt\
F 2 no 704 1 00000001 00000003 562
13248 S 1 48000 -inf -inf 000033C0 0xabab8480 0x0 0x600 0\
F 6 yes 9345 3
00000001 00000001 576 128 A 1 48000 0 0 0376AA00 0xabab8480 0x0 0x400 256
* find the sample app pid
* check with result on step 1.
if there is one "F" in the front of your echo pid, **player** is on fast audio path
For fast audio capture [it is totally different story], if you do **NOT** see
com.example.nativeaudio W/AudioRecord﹕ AUDIO_INPUT_FLAG_FAST denied by client
in your logcat output when you are creating audio recorder, you could "assume" you are on the fast path.
If your system image was built with muted ALOGW, you will not be able to see the above warning message.
1. execute adb shell ps | grep echo
- find the sample app pid
- check with result on step 1.\
if there is one "F" in the front of your echo
pid, **player** is on fast audio path\
For fast audio capture \[it is totally
different story\], if you do **NOT** see\
com.example.nativeaudio
W/AudioRecord﹕ AUDIO_INPUT_FLAG_FAST denied by client\
in your logcat output
when you are creating audio recorder, you could "assume" you are on the fast
path.\
If your system image was built with muted ALOGW, you will not be able
to see the above warning message.
## Tune-ups
Tune-ups
--------
A couple of knobs in the code for lower latency purpose:
* audio buffer size
* number of audio buffers cached before kicking start player
The lower you go with them, the lower latency you get and also the lower budget for audio processing. All audio processing has to be completed in the time period they are captured / played back, plus extra time needed for:
* audio driver
* audio flinger framework,
* bufferqueue callbacks etc
Besides those, the irregularity of the buffer queue player/capture callback time is another factor. The callback from openSL may not as regular as you assumed, the more irregularity it is, the more likely have choopy audio. To fight that, more buffering is needed, which defeats the low-latency purpose! The low latency path is highly tuned up so you have better chance to get more regular callbacks. You may experiment with your platform to find the best parameters for lower latency and continuously playback audio experience.
The app capture and playback on the same device [most of times the same chip], capture and playback clocks are assumed synchronized naturally [so we are not dealing with it]
Credits
-------
* The sample is greatly inspired by native-audio sample
* Don Turner @ Google for the helping of low latency path
* Ian Ni-Lewis @ Google for producer/consumer queue and many others
- audio buffer size
- number of audio buffers cached before kicking start player The lower you go
with them, the lower latency you get and also the lower budget for audio
processing. All audio processing has to be completed in the time period they
are captured / played back, plus extra time needed for:
- audio driver
- audio flinger framework,
- bufferqueue callbacks etc Besides those, the irregularity of the buffer queue
player/capture callback time is another factor. The callback from openSL may
not as regular as you assumed, the more irregularity it is, the more likely
have choopy audio. To fight that, more buffering is needed, which defeats the
low-latency purpose! The low latency path is highly tuned up so you have
better chance to get more regular callbacks. You may experiment with your
platform to find the best parameters for lower latency and continuously
playback audio experience. The app capture and playback on the same device
\[most of times the same chip\], capture and playback clocks are assumed
synchronized naturally \[so we are not dealing with it\]
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Credits
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- The sample is greatly inspired by native-audio sample
- Don Turner @ Google for the helping of low latency path
- Ian Ni-Lewis @ Google for producer/consumer queue and many others
## Support
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,52 +1,61 @@
Bitmap Plasma
=============
Bitmap Plasma is an Android sample that uses JNI to render a plasma effect in an Android [Bitmap](http://developer.android.com/reference/android/graphics/Bitmap.html) from C code.
# Bitmap Plasma
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
Bitmap Plasma is an Android sample that uses JNI to render a plasma effect in an
Android
[Bitmap](http://developer.android.com/reference/android/graphics/Bitmap.html)
from C code.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,69 +1,73 @@
NdkCamera Sample
=============
Two API samples:
- texture-view:
Preview NDK camera image with [Android TextureView](https://developer.android.com/reference/android/view/TextureView.html)
- basic:
A basic NdkCamera sample to preview camera images with AReadImage and take jpeg photos.
Exposure and sensitivity are adjustable for preview, however capturing photos is in auto mode
(it could be adjustable with similar method as used for preview).
# NdkCamera Sample
Two API samples:
- texture-view: Preview NDK camera image with
[Android TextureView](https://developer.android.com/reference/android/view/TextureView.html)
- basic: A basic NdkCamera sample to preview camera images with AReadImage and
take jpeg photos. Exposure and sensitivity are adjustable for preview, however
capturing photos is in auto mode (it could be adjustable with similar method
as used for preview).
## Other Resources
Other Resources
---------------
- Getting familiar with the 5 Camera2 objects
![Camera2 API Model](Camera2ProgrammingModel.png)
![Camera2 API Model](Camera2ProgrammingModel.png)
- [Camera2 blogs](https://medium.com/androiddevelopers/camera-enumeration-on-android-9a053b910cb5)
- [Camera2 Java
documentation](https://developer.android.com/reference/android/hardware/camera2/package-summary)
- [Camera2 Java documentation](https://developer.android.com/reference/android/hardware/camera2/package-summary)
Pre-requisites
--------------
- Android Studio 2.3.0+ with [NDK-r15+](https://developer.android.com/ndk/) bundle
## Pre-requisites
- Android Studio 2.3.0+ with [NDK-r15+](https://developer.android.com/ndk/)
bundle
- Android device running android-24+
Getting Started
---------------
1. Download Android Studio from [latest stable release](http://developer.android.com/sdk/index.html) or [canary](http://tools.android.com/download/studio/canary)
## Getting Started
1. Download Android Studio from
[latest stable release](http://developer.android.com/sdk/index.html) or
[canary](http://tools.android.com/download/studio/canary)
1. Launch Android Studio
1. Select "Import project (Eclipse ADT, Gradle,etc)"
1. Browse into downloaded sample directory, select webp/build.gradle
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
## Screenshots
Screenshots
-----------
![screenshot](ndkCamera.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
For generic questions about Android Camera and other feedbacks, please go to
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-camera)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,19 +1,22 @@
display-p3 ImageView Sample
==========================
A sample to view Display P3 images on Android devices. If Android OS and device both support display P3 mode, two versions of the image will be displayed:
# display-p3 ImageView Sample
A sample to view Display P3 images on Android devices. If Android OS and device
both support display P3 mode, two versions of the image will be displayed:
- Display P3 view on the left hand side
- sRGB view on the right hand side
Pre-requisites
--------------
- [Android Oreo](https://developer.android.com/about/versions/oreo/index.html) (API level >= 26) device that supports wide color gamut mode
(Implemented on Android Oreo with Display P3 color space)
## Pre-requisites
- [Android Oreo](https://developer.android.com/about/versions/oreo/index.html)
(API level >= 26) device that supports wide color gamut mode (Implemented on
Android Oreo with Display P3 color space)
- Android Studio 3.5.2+
- Android [NDK-r20+](https://developer.android.com/ndk/downloads/index.html)
Getting Started
---------------
1. Enable "Natural" mode for "Color" configuration: Settings > Display > Colors
## Getting Started
1. Enable "Natural" mode for "Color" configuration: Settings > Display > Colors
1. [Download Android Studio](https://developer.android.com/studio/index.html)
1. [Download Android NDK-r15+](https://developer.android.com/ndk/downloads/index.html)
1. [Download source code](http://www.github.com/googlesamples/android-ndk)
@@ -21,23 +24,29 @@ Getting Started
1. "File"-->"New" --> "Import Project", select display-p3/build.gradle
1. "Run" --> "Run 'app'"
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Description
-----------
This sample creates [Display P3](https://developer.android.com/about/versions/oreo/android-8.0.html#cm)
EGLContext_, then creates 2 textures for each PNG file under "assets" folder, and on Android devices support Display P3:
## Description
This sample creates
[Display P3](https://developer.android.com/about/versions/oreo/android-8.0.html#cm)
EGLContext\_, then creates 2 textures for each PNG file under "assets" folder,
and on Android devices support Display P3:
- the first is in Display P3 image mode,
- the second is in sRGB mode. The sRGB texture is created by transforming the
original Display P3 image into CIExyz 1931 color space, clamping colors in
sRGB color space, then transforming it back to Display P3 color space to display.
- the second is in sRGB mode. The sRGB texture is created by transforming the
original Display P3 image into CIExyz 1931 color space, clamping colors in
sRGB color space, then transforming it back to Display P3 color space to
display.
For Android Devices that does NOT support display P3, both textures will be in sRGB (identical view)
For Android Devices that does NOT support display P3, both textures will be in
sRGB (identical view)
The Display P3 mode is turned on when application requests a window surface of
type `EGL_GL_COLORSPACE_DISPLAY_P3_EXT`:
The Display P3 mode is turned on when application requests a window surface of type
`EGL_GL_COLORSPACE_DISPLAY_P3_EXT`:
```java
std::vector<EGLint> attributes;
attributes.push_back(EGL_GL_COLORSPACE_KHR);
@@ -47,72 +56,82 @@ The Display P3 mode is turned on when application requests a window surface of t
engine->display_, config, engine->app->window, attributes.data());
```
Android 10+ supports EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, the sample detects the extension and enables it
instead of EGL_GL_COLORSPACE_DISPLAY_P3_EXT. The difference between the two is on how to handle OETF/EOTF ( gamma like thing):
- EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT tells hardware to bypass OETF/EOTF transfer functions
- EGL_GL_COLORSPACE_DISPLAY_P3_EXT enables transfer functions when writing to framebuffers.
Note that the implementation on Android 8 and Android 9 for EGL_GL_COLORSPACE_DISPLAY_P3_EXT may varies on your test devices,
if you see the color washing out or too dark, you could change the code to alter OETF/EOTF functionality and texture's setting
to get a correct setting fit your system.
All images under the assets folder are *assumed* to be already encoded in Display P3 color
space:
Android 10+ supports EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, the sample
detects the extension and enables it instead of
EGL_GL_COLORSPACE_DISPLAY_P3_EXT. The difference between the two is on how to
handle OETF/EOTF ( gamma like thing):
- EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT tells hardware to bypass
OETF/EOTF transfer functions
- EGL_GL_COLORSPACE_DISPLAY_P3_EXT enables transfer functions when writing to
framebuffers. Note that the implementation on Android 8 and Android 9 for
EGL_GL_COLORSPACE_DISPLAY_P3_EXT may varies on your test devices, if you see
the color washing out or too dark, you could change the code to alter
OETF/EOTF functionality and texture's setting to get a correct setting fit
your system.
All images under the assets folder are *assumed* to be already encoded in
Display P3 color space:
- gamma value : 2.2
- Display P3 color space with D65 as white reference point
To add new images, simply drop the new file into this folder. Please note that all decompressing
is performed on CPU at the start up time: it takes time when there are lot of image files.
Some of the images are from [codelogic's wide-gamut-tests](https://github.com/codelogic/wide-gamut-tests)
repo. On Display P3 capable devices, details inside red and green areas are noticeably different, blue area is
almost the same, just as expected.
To add new images, simply drop the new file into this folder. Please note that
all decompressing is performed on CPU at the start up time: it takes time when
there are lot of image files.
Some of the images are from
[codelogic's wide-gamut-tests](https://github.com/codelogic/wide-gamut-tests)
repo. On Display P3 capable devices, details inside red and green areas are
noticeably different, blue area is almost the same, just as expected.
Changing display mode:
- Tap on image to show/hide (Display P3 mode or sRGB mode)
- Swipe up/down to rotate through image files
More About Wide Color Gamut
- [Color Management in Android Oreo](https://developer.android.com/about/versions/oreo/android-8.0.html#cm)
- [Understanding Color (talk at Google I/O 2017)](https://www.youtube.com/watch?v=r8NeG0wmFXM)
- [Enhancing Graphics with Wide Color Content](https://developer.android.com/training/wide-color-gamut/index.html)
Version History
---------------
| Version | Date | Note |
## Version History
| Version | Date | Note |
| --------- | -------- | -------------------------------- |
| 1.0 | 07/2017 | Initial Version |
| 1.0 | 07/2017 | Initial Version |
| --------- | -------- | -------------------------------- |
| 1.1 | 12/2019 | Added P3_PASSTHROUGH_EXT |
| 1.1 | 12/2019 | Added P3_PASSTHROUGH_EXT |
## Support
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2017 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,135 +1,137 @@
Endless Tunnel
==============
# Endless Tunnel
Endless Tunnel is a sample game that shows how to:
- use the Android Studio C++ support
- implement a game using Android native glue
- implement joystick support, including robust DPAD navigation for non-touch screens
- implement joystick support, including robust DPAD navigation for non-touch
screens
It is NOT the goal of this sample to show the best way to write the
game logic, load resources, etc. The game itself was intentionally
kept rudimentary in order to keep the focus on the Android Studio C++
integration. For example, this game contains textures and geometry
hard-coded in code, which works for small demo games like this one,
but doesn't scale well to real games.
It is NOT the goal of this sample to show the best way to write the game logic,
load resources, etc. The game itself was intentionally kept rudimentary in order
to keep the focus on the Android Studio C++ integration. For example, this game
contains textures and geometry hard-coded in code, which works for small demo
games like this one, but doesn't scale well to real games.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/).
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Dependencies
------------
## Dependencies
### GLM LIBRARY
This project uses the OpenGL Mathematics (GLM) library, available at:
https://github.com/g-truc/glm
```
https://github.com/g-truc/glm
```
For more information about this library and its license, please see
[readme.md](https://github.com/g-truc/glm/blob/master/readme.md) and
[copying](https://github.com/g-truc/glm/blob/master/copying.txt).
Acknowledgements
----------------
Most of this code was written by [Bruno Oliveira](https://plus.google.com/+BrunoOliveira).
## Acknowledgements
Walkthrough
-----------
Source code is under app, it only contains C++ code, which is
sitting at its default location (same as for other samples) at
app/cpp.
Most of this code was written by
[Bruno Oliveira](https://plus.google.com/+BrunoOliveira).
The game starts at the android_main function,
defined in android_main.cpp, like any standard NDK game.
## Walkthrough
Source code is under app, it only contains C++ code, which is sitting at its
default location (same as for other samples) at app/cpp.
The game starts at the android_main function, defined in android_main.cpp, like
any standard NDK game.
### Scenes And The Scene Manager
We have a singleton class called SceneManager. As the name says, it's
the class that manages scenes. There's always an active Scene, and
the scene determines what's visible onscreen and how the game reacts
to input. The main menu is a scene, the gameplay is another scene.
We have a singleton class called SceneManager. As the name says, it's the class
that manages scenes. There's always an active Scene, and the scene determines
what's visible onscreen and how the game reacts to input. The main menu is a
scene, the gameplay is another scene.
As the game runs, the display might be initialized and terminated
multiple times, corresponding, for example, to the app losing focus
and being brought back into focus. This is why the SceneManager
(and the Scene's) have the notion of StartGraphics() and KillGraphics().
These two methods may be called multiple times along the lifetime of
a scene. So everything that has to do with graphics context (like
shaders, textures, etc) has to be initialized in StartGraphics(),
As the game runs, the display might be initialized and terminated multiple
times, corresponding, for example, to the app losing focus and being brought
back into focus. This is why the SceneManager (and the Scene's) have the notion
of StartGraphics() and KillGraphics(). These two methods may be called multiple
times along the lifetime of a scene. So everything that has to do with graphics
context (like shaders, textures, etc) has to be initialized in StartGraphics(),
and has to be torn down in KillGraphics().
The NativeEngine::InitDisplay function is where we set up OpenGL
for our game, and call StartGraphics() on the active scene.
The NativeEngine::KillGLObjects is where we call KillGraphics() on the active
scene.
The NativeEngine::InitDisplay function is where we set up OpenGL for our game,
and call StartGraphics() on the active scene. The NativeEngine::KillGLObjects is
where we call KillGraphics() on the active scene.
Input arrives by way of the NativeEngine::HandleInput function, which
does some basic input classification and delivers the input to
the scene manager. Incidentally, here we also synthesise DPAD events based
on the joystick hat axes (many game controllers generate hat events
when you press the directional pad), because that way we can use that
directional pad to drive UI navigation in the main screen.
Input arrives by way of the NativeEngine::HandleInput function, which does some
basic input classification and delivers the input to the scene manager.
Incidentally, here we also synthesise DPAD events based on the joystick hat axes
(many game controllers generate hat events when you press the directional pad),
because that way we can use that directional pad to drive UI navigation in the
main screen.
Take a look at scene_manager.cpp, scene.cpp, etc to familiarize yourself
with them.
Take a look at scene_manager.cpp, scene.cpp, etc to familiarize yourself with
them.
### Geometry And Rendering
The game's geometry is represented by VBOs and IBOs. A VBO is represented
by the VertexBuf class, and an IBO is represented by an IndexBuf.
A shader is represented by the Shader class, of which TrivialShader is
a concrete example.
The game's geometry is represented by VBOs and IBOs. A VBO is represented by the
VertexBuf class, and an IBO is represented by an IndexBuf. A shader is
represented by the Shader class, of which TrivialShader is a concrete example.
Now, onto rendering. Everything in the game is rendered by a Shader.
Normally, to use a Shader, you call BeginRender() and give it a
VertexBuf. This means you will be rendering one or more subsets of that
geometry. After that, call Render(ibuf, mat) where ibuf is the IndexBuffer
that represents the part of the geometry you want to render, and
mat is the transformation matrix. You can call Render() multiple times to
render different subsets of the geometry with different matrices.
When you're done, you call the shader's EndRender() method.
Normally, to use a Shader, you call BeginRender() and give it a VertexBuf. This
means you will be rendering one or more subsets of that geometry. After that,
call Render(ibuf, mat) where ibuf is the IndexBuffer that represents the part of
the geometry you want to render, and mat is the transformation matrix. You can
call Render() multiple times to render different subsets of the geometry with
different matrices. When you're done, you call the shader's EndRender() method.
As a simpler alternative when you only want to render a single copy
of an object that's defined by a VertexBuffer and IndexBuffer pair,
just call RenderSimpleGeom(), which takes a matrix and a SimpleGeom
object (which, in turn, is just a pair of VertexBuffer and IndexBuffer).
As a simpler alternative when you only want to render a single copy of an object
that's defined by a VertexBuffer and IndexBuffer pair, just call
RenderSimpleGeom(), which takes a matrix and a SimpleGeom object (which, in
turn, is just a pair of VertexBuffer and IndexBuffer).
The shader subclass is responsible for knowing what to do to render
a geometry. For example, if the shader needs texture coordinates, it will
query the geometry for texture coordinates as necessary -- if it doesn't
have them, it will throw an error (that being just an euphemism for
an ugly native crash). So, yes, you have to be careful that the geometry
you're feeding to a shader has the data that's needed by that shader.
The shader subclass is responsible for knowing what to do to render a geometry.
For example, if the shader needs texture coordinates, it will query the geometry
for texture coordinates as necessary -- if it doesn't have them, it will throw
an error (that being just an euphemism for an ugly native crash). So, yes, you
have to be careful that the geometry you're feeding to a shader has the data
that's needed by that shader.
Particularly, TrivialShader only needs position and color info for
each vertex. The more complex OurShader class (in jni/our_shader.cpp)
needs texture coordinates.
Particularly, TrivialShader only needs position and color info for each vertex.
The more complex OurShader class (in jni/our_shader.cpp) needs texture
coordinates.
### The Normalized 2d Coord System
For all 2D rendering, we use a normalized coordinate system where
the bottom-left of the screen is (0,0), the X coordinate increases
to the right and the Y coordinate increases upwards. The Y coordinate
of the top of the screen is defined to be 1.0. The X coordinate of
the right side of the screen is the screen's aspect ratio. So,
on a 4:3 screen, these are the coordinates of the four corners
of the screen:
For all 2D rendering, we use a normalized coordinate system where the
bottom-left of the screen is (0,0), the X coordinate increases to the right and
the Y coordinate increases upwards. The Y coordinate of the top of the screen is
defined to be 1.0. The X coordinate of the right side of the screen is the
screen's aspect ratio. So, on a 4:3 screen, these are the coordinates of the
four corners of the screen:
```
(0.000,1.000) (1.333,1.000)
@@ -142,9 +144,9 @@ of the screen:
(0.000,0.000) (1.333,0.000)
```
What this means is that Y=0.5 is always the vertical center of the
screen regardless of the screen size, and that X=aspect/2 is always
the horizontal center of the screen, regardless of physical screen size.
What this means is that Y=0.5 is always the vertical center of the screen
regardless of the screen size, and that X=aspect/2 is always the horizontal
center of the screen, regardless of physical screen size.
This coordinate system is set up like this:
@@ -166,42 +168,44 @@ This coordinate system is set up like this:
### The Main Menu
The game's main menu scene is in welcome_scene.cpp. It renders
all the buttons on the interface and manages the navigation. It can
also show popups ("About", "Story", "Play").
The game's main menu scene is in welcome_scene.cpp. It renders all the buttons
on the interface and manages the navigation. It can also show popups ("About",
"Story", "Play").
### Game Logic
The whole game logic is contained in play_scene.cpp. We won't dive into a
full discussion of it, but start reading from the PlayScene::DoFrame() method
and it should become clear. It's a standard game loop that handles
input, updates the world, checks for collisions and renders.
The whole game logic is contained in play_scene.cpp. We won't dive into a full
discussion of it, but start reading from the PlayScene::DoFrame() method and it
should become clear. It's a standard game loop that handles input, updates the
world, checks for collisions and renders.
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,14 +1,13 @@
Exceptions
==========
# Exceptions
This Android sample shows how to handle exceptions across the JNI boundary.
Handling native exceptions
--------------------------
## Handling native exceptions
Native exceptions can be caught in JNI methods and re-thrown in the JVM.
Because uncaught native exceptions will cause your app to crash, we recommend
catching **all** exceptions as a fail-safe. You may also want to catch
instances of `std::exception` or your own exception interface:
Native exceptions can be caught in JNI methods and re-thrown in the JVM. Because
uncaught native exceptions will cause your app to crash, we recommend catching
**all** exceptions as a fail-safe. You may also want to catch instances of
`std::exception` or your own exception interface:
```C++
extern "C" JNIEXPORT void JNICALL
@@ -44,35 +43,37 @@ in the Android platform's libnativehelper, from which
[exception_helper.cpp](exceptions/app/src/main/cpp/exception_helper.cpp) are
adapted.
Screenshot
-----------
## Screenshot
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2022 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,61 +1,69 @@
gles3jni
=========
gles3jni is an Android C++ sample that demonstrates how to use OpenGL ES 3.0 from JNI/native code.
# gles3jni
The OpenGL ES 3.0 rendering path uses a few new features compared to the
OpenGL ES 2.0 path:
- Instanced rendering and vertex attribute divisor to reduce the number of
draw calls and uniform changes.
- Vertex array objects to reduce the number of calls required to set up
vertex attribute state on each frame.
gles3jni is an Android C++ sample that demonstrates how to use OpenGL ES 3.0
from JNI/native code.
The OpenGL ES 3.0 rendering path uses a few new features compared to the OpenGL
ES 2.0 path:
- Instanced rendering and vertex attribute divisor to reduce the number of draw
calls and uniform changes.
- Vertex array objects to reduce the number of calls required to set up vertex
attribute state on each frame.
- Explicit assignment of attribute locations, eliminating the need to query
assignments.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 1.3+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,56 +1,63 @@
Hello GL2
=========
# Hello GL2
Hello GL2 is an Android C++ sample that draws a triangle using GLES 2.0 API.
It uses JNI to do the rendering in C++ over a
[GLSurfaceView](http://developer.android.com/reference/android/opengl/GLSurfaceView.html)
created from a regular Android Java Activity.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
Pre-requisites
--------------
- Android Studio 2.2 preview+ with [NDK](https://developer.android.com/ndk/) bundle.
## Pre-requisites
- Android Studio 2.2 preview+ with [NDK](https://developer.android.com/ndk/)
bundle.
## Getting Started
Getting Started
---------------
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,52 +1,58 @@
Hello JNI
=========
Hello JNI is an Android sample that uses JNI to call C code from a Android Java Activity.
# Hello JNI
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
For how to use Android Studio, refer to [Hello-CMake codelab](https://codelabs.developers.google.com/codelabs/android-studio-cmake/index.html)
Hello JNI is an Android sample that uses JNI to call C code from a Android Java
Activity.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support. For how to use Android Studio, refer to
[Hello-CMake codelab](https://codelabs.developers.google.com/codelabs/android-studio-cmake/index.html)
## Pre-requisites
Pre-requisites
--------------
- Android Studio 4.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure.../SDK Location*, click *Download* or *Select NDK location*.
1. Open *File/Project Structure.../SDK Location*, click *Download* or *Select
NDK location*.
1. Click *File/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2022 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,54 +1,62 @@
Hello JNI Callback
==================
This sample is an add-on to Hello JNI sample to demonstrate calling back to Java from C code
# Hello JNI Callback
This sample is an add-on to Hello JNI sample to demonstrate calling back to Java
from C code
- create a java class instance from C code
- call java class static and non-static member functions
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,85 +1,104 @@
hello-libs
=========
hello-libs is a sample that shows you how to manage 3rd party C/C++ libraries with Android Studio.
# hello-libs
Introduction
------------
This sample uses the [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with external library support. It demos how to:
hello-libs is a sample that shows you how to manage 3rd party C/C++ libraries
with Android Studio.
* include a pre-built static library (gmath) in your app
* include a pre-built shared library (gperf) in your app
## Introduction
This sample uses the
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with external library support. It demos how to:
- include a pre-built static library (gmath) in your app
- include a pre-built shared library (gperf) in your app
## Description
Description
-----------
The sample includes 2 modules:
* app -- imports a shared library (libgperf.so) and a static library (libgmath.a) from the `distribution` folder
* gen-libs -- contains the source code and CMake build script for the gmath and gperf example libraries. The resulting binaries are copied into the `distribution` folder. By default, gen-libs module is disabled in setting.gradle and app/build.gradle, so it won't show up in Android Studio IDE. If re-generating lib is desirable, follow comments inside settings.gradle and app/build.gradle to enable this module, generate libs, then disable it again to avoid unnecessary confusion.
The main goal of the sample is to demo how to use 3rd party libs, it is not to demonstrate lib package generation. Toward that goal, the pre-built libs are included in the `distribution` folder.
- app -- imports a shared library (libgperf.so) and a static library
(libgmath.a) from the `distribution` folder
- gen-libs -- contains the source code and CMake build script for the gmath and
gperf example libraries. The resulting binaries are copied into the
`distribution` folder. By default, gen-libs module is disabled in
setting.gradle and app/build.gradle, so it won't show up in Android Studio
IDE. If re-generating lib is desirable, follow comments inside settings.gradle
and app/build.gradle to enable this module, generate libs, then disable it
again to avoid unnecessary confusion.
When importing libraries into your app, include the following in your app's `CMakeLists.txt` file (in the following order):
The main goal of the sample is to demo how to use 3rd party libs, it is not to
demonstrate lib package generation. Toward that goal, the pre-built libs are
included in the `distribution` folder.
* import libraries as static or shared(using `add_library`)
* configure each library binary location(using `set_target_properties`)
* configure each library headers location (using `target_include_directories`)
When importing libraries into your app, include the following in your app's
`CMakeLists.txt` file (in the following order):
If you are using Android Gradle Plugin earlier than version 4.0.0,
for shared libraries, you need to explicitly notify gradle to pack them into APK.
One simple way is to include the shared lib directory into application's jniLibs directory:
* jniLibs.srcDirs = ['../distribution/gperf/lib']
- import libraries as static or shared(using `add_library`)
- configure each library binary location(using `set_target_properties`)
- configure each library headers location (using `target_include_directories`)
If you are using Android Gradle Plugin earlier than version 4.0.0, for shared
libraries, you need to explicitly notify gradle to pack them into APK. One
simple way is to include the shared lib directory into application's jniLibs
directory:
- jniLibs.srcDirs = \['../distribution/gperf/lib'\]
## Pre-requisites
Pre-requisites
--------------
- Android Studio 3.0.0 with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Note that if you do want to regenerate the two libraries, follow these steps:
1. in settings.gradle file, enable the line `include :gen-libs`
1. in app/build.gradle file, enable the line `api project(':gen-libs')`
1. build the project
1. undo the first 2 steps
1. clean up temprorary build files with `rm -fr app/build app/.cxx`
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,69 +1,78 @@
Hello Neon
==========
Hello Neon is an Android sample that uses ARM NEON for fir filter implementation:
- identify NEON files in source tree, they would be just normal c/c++ source files
- append -mfpu=neon to CMake compile flag for neon source files.
This is different from android.mk, in that:
- *.c.neon is fake file name; cmake does not need that mechanism
# Hello Neon
Hello Neon is an Android sample that uses ARM NEON for fir filter
implementation:
- identify NEON files in source tree, they would be just normal c/c++ source
files
- append -mfpu=neon to CMake compile flag for neon source files. This is
different from android.mk, in that:
- \*.c.neon is fake file name; cmake does not need that mechanism
If there are lot of NEON files in the project, make a NEON lib:
- turn NEON compile flags for the lib
- let the rest of the project use the NEON libs
(this approach is not shown)
- let the rest of the project use the NEON libs (this approach is not shown)
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*, then click *Download* or *Select NDK location*.
1. Click *Build/Generate Signed APK* to [build release APK](https://developer.android.com/studio/publish/app-signing.html#sign-apk).
1. Open *File/Project Structure...*, then click *Download* or *Select NDK
location*.
1. Click *Build/Generate Signed APK* to
[build release APK](https://developer.android.com/studio/publish/app-signing.html#sign-apk).
1. Install your signed APK with *adb install -r your-signed-apk*.
1. Run it on your target device
Notes:
- Build for release version(signed APK will do that) to view the performance numbers
- The performance number may vary with different platforms
- On x86 platforms, the purpose is to demo the neon code portability: neon performance number may not be better than that of the "C" version
Screenshots
-----------
- Build for release version(signed APK will do that) to view the performance
numbers
- The performance number may vary with different platforms
- On x86 platforms, the purpose is to demo the neon code portability: neon
performance number may not be better than that of the "C" version
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,71 +1,75 @@
Hello Oboe
=========
# Hello Oboe
Hello Oboe is an Android sample that uses the
[Oboe](https://github.com/google/oboe) library to play audio natively. Oboe
wraps both AAudio and OpenSLES to help developers play and record audio in
performance sensitive contexts across Android versions. The Oboe
repository has more information about how to fully take advantage of the Oboe API,
as well as more in-depth examples and documentation.
performance sensitive contexts across Android versions. The Oboe repository has
more information about how to fully take advantage of the Oboe API, as well as
more in-depth examples and documentation.
This sample uses the Studio Prefab feature to download pre-built Oboe library
from [Google Maven](https://maven.google.com/web/index.html), feel free to
checkout Prefab steps in
This sample uses the Studio Prefab feature to download pre-built Oboe library from [Google Maven](https://maven.google.com/web/index.html),
feel free to checkout Prefab steps in
- gradle.properties
- app/build.gradle
- app/src/main/cpp/CMakeLists.txt
If you like to build your app with the Oboe library source code, refer to the examples in the Oboe
repository.
Pre-requisites
--------------
If you like to build your app with the Oboe library source code, refer to the
examples in the Oboe repository.
## Pre-requisites
- Android Studio 4.0+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshot
------------
## Screenshot
![screenshot](screenshot.png)
## Using the App
Using the App
--------------
Tap and hold the screen to play audio. The app will render a 440Hz sine wave
while the screen is being pressed.
## Support
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2019 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,61 +1,76 @@
Hello VK
=========
Hello VK is an Android C++ sample that draws the simple, but traditional Hello World Triangle.
# Hello VK
Aside from the base functionality the source code also covers convenient features such as:
Hello VK is an Android C++ sample that draws the simple, but traditional Hello
World Triangle.
Aside from the base functionality the source code also covers convenient
features such as:
- Vulkan validation layers. See section below for information on how to enable
these
- Vulkan pre-rotation to enable fast and seamless screen rotation implemented on
the application side. You can read more about it here:
https://developer.android.com/games/optimize/vulkan-prerotation
## Pre-requisites
- Vulkan validation layers. See section below for information on how to enable these
- Vulkan pre-rotation
to enable fast and seamless screen rotation implemented on the application side. You can read more about it here:
https://developer.android.com/games/optimize/vulkan-prerotation
Pre-requisites
--------------
- Android Studio 4.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
1. Click *File/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
---------------
## Screenshots
![Vulkan Triangle example](documentation-assets/example-triangle.png)
## Validation layers
Validation layers
-------
As the validation layer is a sizeable download, we chose to not ship them within the apk. As such in order to enable validation layer, please follow the simple steps below:
As the validation layer is a sizeable download, we chose to not ship them within
the apk. As such in order to enable validation layer, please follow the simple
steps below:
1. Download the latest android binaries from:
https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases
2. Place them in their respective ABI folders located in: app/src/main/jniLibs
3. Go to hellovk.h, search for 'bool enableValidationLayers = false' and toggle that to true.
https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases
1. Place them in their respective ABI folders located in: app/src/main/jniLibs
1. Go to hellovk.h, search for 'bool enableValidationLayers = false' and toggle
that to true.
Extra information:
-------
As Vulkan is well documented we will not provide detailed instructions regarding the innerworkings of Vulkan. You should however, find useful comments and references regarding the android to vulkan bridge. We chose to use Android Glue for a seamless experience. More details here:
## Extra information:
As Vulkan is well documented we will not provide detailed instructions regarding
the innerworkings of Vulkan. You should however, find useful comments and
references regarding the android to vulkan bridge. We chose to use Android Glue
for a seamless experience. More details here:
https://developer.android.com/reference/games/game-activity/group/android-native-app-glue
These vulkan tutorials should hopefully cover everything needed to understand the workings of the Vulkan app:
https://vulkan-tutorial.com
These vulkan tutorials should hopefully cover everything needed to understand
the workings of the Vulkan app: https://vulkan-tutorial.com
https://vkguide.dev/docs/chapter-1/vulkan_init_flow/
Lastly, you will notice that the Kotlin file is somewhat redundant. Luckily, if you do not require any additional/custom application behaviour, the Android(Kotlin) source files can be completely removed and the AndroidManifest.xml tweaked as specified here:
Lastly, you will notice that the Kotlin file is somewhat redundant. Luckily, if
you do not require any additional/custom application behaviour, the
Android(Kotlin) source files can be completely removed and the
AndroidManifest.xml tweaked as specified here:
https://developer.android.com/ndk/samples/sample_na
## Support
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)

View File

@@ -1,52 +1,60 @@
Native Activity
===============
Native Activity is an Android sample that initializes a GLES 2.0 context and reads accelerometer data from C code using [Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html).
# Native Activity
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
Native Activity is an Android sample that initializes a GLES 2.0 context and
reads accelerometer data from C code using
[Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html).
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,59 +1,70 @@
Native Audio
============
Native Audio is an Android sample that plays and records sounds with the C++ OpenSLES API using JNI. The recorder / players created are not in fast audio path.
# Native Audio
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
Native Audio is an Android sample that plays and records sounds with the C++
OpenSLES API using JNI. The recorder / players created are not in fast audio
path.
***Note that OpenSL ES is [deprecated from Android 11](https://developer.android.com/preview/features#deprecate-opensl), developers are recommended to use [Oboe](https://github.com/google/oboe) library instead.***
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
***Note that OpenSL ES is
[deprecated from Android 11](https://developer.android.com/preview/features#deprecate-opensl),
developers are recommended to use [Oboe](https://github.com/google/oboe) library
instead.***
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Known Issues
-----------
- URI Player streaming is [broken](https://github.com/googlesamples/android-ndk/issues/229)
## Known Issues
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
- URI Player streaming is
[broken](https://github.com/googlesamples/android-ndk/issues/229)
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
## Support
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,63 +1,69 @@
Native Codec
============
Native Codec is an Android C++ sample that uses the Native Media Codec API to play a video.
# Native Codec
Native Codec is an Android C++ sample that uses the Native Media Codec API to
play a video.
encoded stream files are under app/src/main/assets/clips one file testfile.mp4
is provided as an example. To add your own files:
encoded stream files are under
app/src/main/assets/clips
one file testfile.mp4 is provided as an example.
To add your own files:
- copy your stream file into app/src/main/assets/
- add your file name to res/strings.xml, "source_array"
- compile and run app
- from android device, select your stream
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
1. Open a terminal prompt and run `adb push testfile.mp4 /sdcard/testfile.mp4` to copy the test video file.
1. Open a terminal prompt and run `adb push testfile.mp4 /sdcard/testfile.mp4`
to copy the test video file.
## Screenshots
Screenshots
-----------
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,66 +1,73 @@
Native Media
============
# Native Media
Native Media is an Android sample that uses OpenMAX AL to play a video.
Note: This sample requires an MPEG-2 Transport Stream file to be
placed in app/src/main/assets/clips/NativeMedia.ts and encoded as:
Note: This sample requires an MPEG-2 Transport Stream file to be placed in
app/src/main/assets/clips/NativeMedia.ts and encoded as:
```
video: H.264 baseline profile
audio: AAC LC stereo
```
For demonstration purposes we have supplied such a .ts file, any
actual stream must be created according to the MPEG-2 specification.
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
For demonstration purposes we have supplied such a .ts file, any actual stream
must be created according to the MPEG-2 specification.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
## Known Issues
Known Issues
------------
- Android-N preoview: native player path is not working, under debug now
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,22 +1,43 @@
Description
-----------
### Introduction
The Native MIDI sample is a simple Android application which demonstrates how to use [the Android Native MIDI API](http://developer.android.com/preview/features/midi), a new feature in Android 29.
## Description
Note that [AMidi](http://developer.android.com/preview/features/midi) is a simple data transport mechanism. It works in terms of streams of bytes and does not impose any MIDI semantics beyond that whole MIDI messages are transported as a unit. Indeed, basic MIDI constructs such as message IDs, or message formatting are not represented in either API. However, since the sample does deal with MIDI semantics, there are definitions and mechanism to support these semantics.
### Introduction
The Native MIDI sample is a simple Android application which demonstrates how to
use
[the Android Native MIDI API](http://developer.android.com/preview/features/midi),
a new feature in Android 29.
Note that [AMidi](http://developer.android.com/preview/features/midi) is a
simple data transport mechanism. It works in terms of streams of bytes and does
not impose any MIDI semantics beyond that whole MIDI messages are transported as
a unit. Indeed, basic MIDI constructs such as message IDs, or message formatting
are not represented in either API. However, since the sample does deal with MIDI
semantics, there are definitions and mechanism to support these semantics.
### An Important Nomenclature Observation
AMidi inherits most of its terminology from the existing Android Java MIDI API. This can cause confusion regarding the naming of port types and their directionality. The Android Java MIDI API regards the directionality of the ports from the perspective of the connected MIDI peripheral, not the perspective of the application. AMidi inherits this perspective so an application uses an AMidiOutputPort to receive MIDI data from the output port of a device and uses an AMidiInputPort to send data to the input port of a device. AMidi uses the verbs “send” and “receive” to make this more clear to the application programmer, and these conventions are used in the NMTb.
Prerequisites
By definition, the Android Native MIDI API requires the use of the Java Native Interface (JNI). It is assumed that anyone implementing a Native MIDI application will be familiar with JNI.
AMidi inherits most of its terminology from the existing Android Java MIDI API.
This can cause confusion regarding the naming of port types and their
directionality. The Android Java MIDI API regards the directionality of the
ports from the perspective of the connected MIDI peripheral, not the perspective
of the application. AMidi inherits this perspective so an application uses an
AMidiOutputPort to receive MIDI data from the output port of a device and uses
an AMidiInputPort to send data to the input port of a device. AMidi uses the
verbs “send” and “receive” to make this more clear to the application
programmer, and these conventions are used in the NMTb. Prerequisites By
definition, the Android Native MIDI API requires the use of the Java Native
Interface (JNI). It is assumed that anyone implementing a Native MIDI
application will be familiar with JNI.
### Hardware Setup
This sample requires an input and an output MIDI device connected to Android devices running Android Qt+. An example configure can be:
This sample requires an input and an output MIDI device connected to Android
devices running Android Qt+. An example configure can be:
![Configure](config.png)
Getting Started
---------------
## Getting Started
1. [Download Android Studio 3.4 beta](http://developer.android.com/sdk/index.html)
1. Launch Android Studio, and install all updates that Studio prompts
1. Open the sample directory.
@@ -24,45 +45,53 @@ Getting Started
1. Click *File/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
**Note for stable Android Studio**
Stable Android Studio does not automatically download and install NDK beta versions; but you could still use it to build this sample with one of the following ways
- switching to the beta update channel by going to Preferences->Check for updates->Configure automatic updates. Once you've changed to the beta channel you should see NDK r20 in the list of SDK Tools.
- manually download [ndk-r20-beta or better](https://developer.android.com/ndk/downloads), then add `ndk.dir=$your-downloaded-ndk-r20-dir` to your `native-midi/local.properties` (this is studio generated file).
**Note for stable Android Studio** Stable Android Studio does not automatically
download and install NDK beta versions; but you could still use it to build this
sample with one of the following ways
- switching to the beta update channel by going to Preferences->Check for
updates->Configure automatic updates. Once you've changed to the beta channel
you should see NDK r20 in the list of SDK Tools.
- manually download
[ndk-r20-beta or better](https://developer.android.com/ndk/downloads), then
add `ndk.dir=$your-downloaded-ndk-r20-dir` to your
`native-midi/local.properties` (this is studio generated file).
## Screenshots
Screenshots
-----------
![screenshot](screenshot.png)
Authors
-------
- pmclean@ of Android team
## Authors
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
- pmclean@ of Android team
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
## Support
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2019 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,52 +1,60 @@
Native Plasma
=============
Native Plasma is an Android sample that renders a plasma effect in a Bitmap from C code using [Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html).
# Native Plasma
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
Native Plasma is an Android sample that renders a plasma effect in a Bitmap from
C code using
[Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html).
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,57 +1,59 @@
Android Neural Networks API Sample
======
# Android Neural Networks API Sample
The samples demonstrate how to use Android NNAPI exported through Android NDK:
- basic: showcase the main NNAPI concept from Android 8
- sequence: showcase the advanced features added in Android 11
Check each module's README.md for additional descriptions and additional requirements.
Check each module's README.md for additional descriptions and additional
requirements.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 4.0+.
- NDK r16+.
- Android API 27+.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
<img src="basic/screenshot.png" width="360">
<img src="sequence/screenshot.png" width="360">
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/android/ndk-samples/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2020 Google LLC
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,8 +1,13 @@
Android Neural Networks API Sample: Basic
======
Android Neural Networks API (NN API) Sample demonstrates basic usages of NN API with a simple model that consists of three operations: two additions and a multiplication.
# Android Neural Networks API Sample: Basic
Android Neural Networks API (NN API) Sample demonstrates basic usages of NN API
with a simple model that consists of three operations: two additions and a
multiplication.
The sums created by the additions are the inputs to the multiplication. In
essence, we are creating a graph that computes: (tensor0 + tensor1) * (tensor2 +
tensor3).
The sums created by the additions are the inputs to the multiplication. In essence, we are creating a graph that computes: (tensor0 + tensor1) * (tensor2 + tensor3).
```java
tensor0 ---+
+--- ADD ---> intermediateOutput0 ---+
@@ -13,19 +18,27 @@ tensor2 ---+ |
tensor3 ---+
```
Two of the four tensors, tensor0 and tensor2 being added are constants, defined in the model. They represent the weights that would have been learned during a training process, loaded from model_data.bin.
Two of the four tensors, tensor0 and tensor2 being added are constants, defined
in the model. They represent the weights that would have been learned during a
training process, loaded from model_data.bin.
The other two tensors, tensor1 and tensor3 will be inputs to the model. Their values will be provided when we execute the model. These values can change from execution to execution.
The other two tensors, tensor1 and tensor3 will be inputs to the model. Their
values will be provided when we execute the model. These values can change from
execution to execution.
Besides the two input tensors, an optional fused activation function can also be defined for ADD and MUL. In this example, we'll simply set it to NONE.
Besides the two input tensors, an optional fused activation function can also be
defined for ADD and MUL. In this example, we'll simply set it to NONE.
The model then has 8 operands:
- 2 tensors that are inputs to the model. These are fed to the two ADD operations.
- 2 tensors that are inputs to the model. These are fed to the two ADD
operations.
- 2 constant tensors that are the other two inputs to the ADD operations.
- 1 fuse activation operand reused for the ADD operations and the MUL operation.
- 2 intermediate tensors, representing outputs of the ADD operations and inputs to the MUL operation.
- 2 intermediate tensors, representing outputs of the ADD operations and inputs
to the MUL operation.
- 1 model output.
Screenshots
-----------
## Screenshots
<img src="screenshot.png" width="480">

View File

@@ -1,6 +1,9 @@
Android Neural Networks API Sample: Sequence
======
Android Neural Networks API (NN API) Sample demonstrates basic usages of NN API with a sequence model that consists of two operations: one addition and one multiplication. This graph is used for computing a single step of accumulating a geometric progression.
# Android Neural Networks API Sample: Sequence
Android Neural Networks API (NN API) Sample demonstrates basic usages of NN API
with a sequence model that consists of two operations: one addition and one
multiplication. This graph is used for computing a single step of accumulating a
geometric progression.
```
sumIn ---+
@@ -10,7 +13,12 @@ stateIn ---+
ratio ---+
```
The ratio is a constant tensor, defined in the model. It represents the weights that would have been learned during a training process. The sumIn and stateIn are input tensors. Their values will be provided when we execute the model. These values can change from execution to execution. To compute the sum of a geometric progression, the graph will be executed multiple times with inputs and outputs chained together.
The ratio is a constant tensor, defined in the model. It represents the weights
that would have been learned during a training process. The sumIn and stateIn
are input tensors. Their values will be provided when we execute the model.
These values can change from execution to execution. To compute the sum of a
geometric progression, the graph will be executed multiple times with inputs and
outputs chained together.
```
+----------+ +----------+ +----------+
@@ -20,13 +28,15 @@ initialState -->| Model |-->| Model |--> -->| Model |--> stateOut
+----------+ +----------+ +----------+
```
Additional Requirements
-----------------------
## Additional Requirements
- Android 11 SDK to compile
- A device running Android 11
Note: This sample uses its own wrapper to access new NNAPI features in Android 11 due to an known issue. This will be updated after the issue is fixed with the next R SDK release.
Note: This sample uses its own wrapper to access new NNAPI features in Android
11 due to an known issue. This will be updated after the issue is fixed with the
next R SDK release.
## Screenshots
Screenshots
-----------
<img src="screenshot.png" width="480">

View File

@@ -1,61 +1,68 @@
Hello-libs
=========
Hello-Libs is an Android sample that demos native lib management in Android Studio.
# Hello-libs
This sample uses the new [Android Studio external C build plugin](http://tools.android.com/tech-docs/external-c-builds)
with external lib support with
* LOCAL_STATIC_LIBRARIES
* LOCAL_SHARED_LIBRARIES
Hello-Libs is an Android sample that demos native lib management in Android
Studio.
This sample uses the new
[Android Studio external C build plugin](http://tools.android.com/tech-docs/external-c-builds)
with external lib support with
- LOCAL_STATIC_LIBRARIES
- LOCAL_SHARED_LIBRARIES
it includes 2 modules:
* app -- uses one shared lib and one static lib from $project/distribution/
* gen-libs -- generates one shared and one static lib, and copy them into $project/distribution
To generate libs, refer to file gen-libs/gen_lib.sh
- app -- uses one shared lib and one static lib from $project/distribution/
- gen-libs -- generates one shared and one static lib, and copy them into
$project/distribution To generate libs, refer to file gen-libs/gen_lib.sh
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,2 +1,2 @@
Known Issue:
URI Player is not working, ( I believe I filed a bug for it, but will confirm later)
Known Issue: URI Player is not working, ( I believe I filed a bug for it, but
will confirm later)

View File

@@ -1,10 +1,10 @@
Prefab Samples
==============
The samples in this directory demonstrate how to create and consume [C/C++
dependencies] with the Android Gradle Plugin. Dependencies are packaged within
AARs using the [Prefab] package format. The Android Gradle Plugin natively
supports producing and consuming these, so you do not need to worry about the
details of the packaging format.
# Prefab Samples
The samples in this directory demonstrate how to create and consume
[C/C++ dependencies] with the Android Gradle Plugin. Dependencies are packaged
within AARs using the [Prefab] package format. The Android Gradle Plugin
natively supports producing and consuming these, so you do not need to worry
about the details of the packaging format.
The individual samples will explain in more detail, but the typical workflow for
a consumer of a native dependency is:
@@ -22,77 +22,73 @@ To produce an AAR that exposes C/C++ APIs:
1. Enable the `prefabPublishing` build feature in your `build.gradle` file.
1. Use `android.prefab` in your `build.gradle` file to declare the names of the
libraries you wish to export and the headers that define their interface.
libraries you wish to export and the headers that define their interface.
To test your packages, follow the steps for package consumers. Note that until
https://issuetracker.google.com/120166563 is fixed it is not possible to depend
on the native components of an AAR generated by another module of the same
project when using Android Studio. Instead, test in a separate project. You can
import the AAR into your test project either [directly](https://developer.android.com/studio/projects/android-library#AddDependency)
import the AAR into your test project either
[directly](https://developer.android.com/studio/projects/android-library#AddDependency)
or by publishing it to a Maven repository.
With that in mind, the samples here collectively demonstrate prefab usage:
* prefab-publishing shows how to create an AAR for distributing native libraries
* prefab-dependency shows how to import native dependencies from [GMaven]
* curl-ssl: for shows to use 2 very specific and important AARs (curl and ssl)
- prefab-publishing shows how to create an AAR for distributing native libraries
- prefab-dependency shows how to import native dependencies from [GMaven]
- curl-ssl: for shows to use 2 very specific and important AARs (curl and ssl)
## Prefab Availability
[C/C++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
[Prefab]: https://google.github.io/prefab
[the formal AAR documentations]: https://developer.android.com/studio/projects/android-library
[GMaven]:(https://maven.google.com/web/index.html?q=ndk#com.android.ndk.thirdparty)
Support for Prefab packages has been available Android Gradle Plugin since
version 4.0:
Prefab Availability
-------------------
- Consuming native dependencies requires AGP 4.0+
- Generating AARs that export native dependencies requires AGP 4.1+
Support for Prefab packages has been available Android Gradle Plugin since version 4.0:
* Consuming native dependencies requires AGP 4.0+
* Generating AARs that export native dependencies requires AGP 4.1+
The AARs used by the samples here are hosted at [Google Maven], but you can host
your AARs anywhere accessible to gradle.
The AARs used by the samples here are hosted at [Google Maven], but you can
host your AARs anywhere accessible to gradle.
## Pre-requisites
[Google Maven]: https://maven.google.com/web/index.html#com.android.ndk.thirdparty
- Android Gradle Plugin 4.0+
- The [Android NDK](https://developer.android.com/ndk/)
Pre-requisites
--------------
Please check for the individial sample's README.md for anything specific to that
sample.
* Android Gradle Plugin 4.0+
* The [Android NDK](https://developer.android.com/ndk/)
## Support
Please check for the individial sample's README.md for anything specific to that sample.
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by [forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2020 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
[c/c++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
[gmaven]: (https://maven.google.com/web/index.html?q=ndk#com.android.ndk.thirdparty)
[google maven]: https://maven.google.com/web/index.html#com.android.ndk.thirdparty
[prefab]: https://google.github.io/prefab

View File

@@ -1,38 +1,30 @@
curl-ssl
========
# curl-ssl
This sample shows how to import [curl] and [OpenSSL] from Google Maven
to display a list of the most recent 10 reviews submitted to AOSP's code review system.
This sample shows how to import [curl] and [OpenSSL] from Google Maven to
display a list of the most recent 10 reviews submitted to AOSP's code review
system.
One of the goals is demonstrate how to handle HTTPS certificates correctly as explained by [this Stack Overflow
post](https://stackoverflow.com/a/30430033/632035): the root certificates
presented by Android since ICS are not in the format OpenSSL expects, so we need
to provide our own certificate file. We do this by downloading curl's cacert.pem
and storing that in our assets directory, as described in [this Stack Overflow
post](https://stackoverflow.com/a/31521185/632035).
One of the goals is demonstrate how to handle HTTPS certificates correctly as
explained by
[this Stack Overflow post](https://stackoverflow.com/a/30430033/632035): the
root certificates presented by Android since ICS are not in the format OpenSSL
expects, so we need to provide our own certificate file. We do this by
downloading curl's cacert.pem and storing that in our assets directory, as
described in
[this Stack Overflow post](https://stackoverflow.com/a/31521185/632035).
If you want to understand how to use C/C++ dependencies with AGP, refer to:
* [prefab-dependency] and [prefab-publishing] samples in the same directory as this one
* [C/C++ dependencies] page for Android documentation for C/C++ dependencies
- [prefab-dependency] and [prefab-publishing] samples in the same directory as
this one
- [C/C++ dependencies] page for Android documentation for C/C++ dependencies
[Prefab]:https://google.github.io/prefab/
[prefab-dependency]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency
[prefab-publishing]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-publishing
[curl]: https://curl.haxx.se/
[OpenSSL]: https://www.openssl.org/
[JsonCpp]: https://github.com/open-source-parsers/jsoncpp
[C/C++ dependencies]:https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
## Pre-requisites
- Android Gradle Plugin 4.0+
- The [Android NDK](https://developer.android.com/ndk/).
Pre-requisites
--------------
* Android Gradle Plugin 4.0+
* The [Android NDK](https://developer.android.com/ndk/).
Getting Started
---------------
## Getting Started
The C++ code in this sample can be built with either CMake (the default for this
project) or ndk-build. To use ndk-build set the `ndkBuild` project property
@@ -42,25 +34,31 @@ either in your `local.properties` file or on the command line by passing the
To build with [Android Studio](http://developer.android.com/sdk/index.html):
1. Open this project in Android Studio.
2. Click *Run/Run 'app'*. If you want to debug/trace code, due to [the SSL lib's known issue with lldb](https://github.com/android/ndk-samples/issues/740), make sure to apply the recommendations there for a smooth debugging experience.
1. Click *Run/Run 'app'*. If you want to debug/trace code, due to
[the SSL lib's known issue with lldb](https://github.com/android/ndk-samples/issues/740),
make sure to apply the recommendations there for a smooth debugging
experience.
To build from the command line:
1. Navigate to this directory in your terminal.
2. Run `./gradlew installDebug` (or `gradlew.bat installDebug` on Windows).
1. Run `./gradlew installDebug` (or `gradlew.bat installDebug` on Windows).
Screenshots
------------
## Screenshots
![screenshot](screenshot.png)
Support
--------
## Support
If you've found an error in these samples, please [file an
issue](https://github.com/android/ndk-samples/issues/new).
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by submitting a pull request
through GitHub. Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for more
details.
[c/c++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
[curl]: https://curl.haxx.se/
[openssl]: https://www.openssl.org/
[prefab-dependency]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency
[prefab-publishing]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-publishing

View File

@@ -1,47 +1,31 @@
prefab-dependency
==================
# prefab-dependency
C/C++ dependencies are C/C++ libraries packed with [Prefab] format into an AAR.
This sample shows how to import [JsonCPP] AAR, one example of [C/C++ dependencies], from Google Maven to an Android project.
This sample shows how to import [JsonCPP] AAR, one example of
[C/C++ dependencies], from Google Maven to an Android project.
[Prefab] could be enabled from Android Gradle Plugin 4.0+. In order to use the feature, follow these 3 steps:
[Prefab] could be enabled from Android Gradle Plugin 4.0+. In order to use the
feature, follow these 3 steps:
* Enable the prefab feature in [gradle.properties]. **Note** that in 4.1+, this needs to be
done with `android.buildFeatures.prefab=true` in the module's `build.gradle` file, for example `app/build.gradle`.
* Declare the dependencies in the app module's [build.gradle] in the same way you as would do with Kotlin/Java
dependencies.
* Add the dependencies into the native module's [Android.mk] or [CMakeLists.txt]
- Enable the prefab feature in [gradle.properties]. **Note** that in 4.1+, this
needs to be done with `android.buildFeatures.prefab=true` in the module's
`build.gradle` file, for example `app/build.gradle`.
- Declare the dependencies in the app module's [build.gradle] in the same way
you as would do with Kotlin/Java dependencies.
- Add the dependencies into the native module's [Android.mk] or [CMakeLists.txt]
From here on, the [headers] and [libraries] in the dependencies are available for your native build system!
From here on, the [headers] and [libraries] in the dependencies are available
for your native build system!
If you want to understand more about C/C++ dependency AARs, go to [C/C++ dependencies] page for
Android Prefab official documentation.
If you want to understand more about C/C++ dependency AARs, go to
[C/C++ dependencies] page for Android Prefab official documentation.
## Pre-requisites
[C/C++ dependencies]:https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
[Prefab]:https://google.github.io/prefab/
[AGP]:https://google.github.io/android-gradle-dsl/current
[android-library]:https://developer.android.com/studio/projects/android-library#AddDependency
[android-dependencies]:https://developer.android.com/studio/build/dependencies
[gradle.properties]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/gradle.properties#L22
[build.gradle]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/build.gradle#L65
[android.mk]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/Android.mk#31
[CMakeLists.txt]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/CMakeLists.txt#L20
[headers]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/app.cpp#L23
[libraries]:https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/CMakeLists.txt#L25
[curl]: https://curl.haxx.se/
[OpenSSL]: https://www.openssl.org/
[JsonCpp]: https://github.com/open-source-parsers/jsoncpp
- Android Gradle Plugin 4.0+
- The [Android NDK](https://developer.android.com/ndk/).
Pre-requisites
--------------
* Android Gradle Plugin 4.0+
* The [Android NDK](https://developer.android.com/ndk/).
Getting Started
---------------
## Getting Started
The C++ code in this sample can be built with either CMake (the default for this
project) or ndk-build. To use ndk-build set the `ndkBuild` project property
@@ -51,25 +35,32 @@ either in your `local.properties` file or on the command line by passing the
To build with [Android Studio](http://developer.android.com/sdk/index.html):
1. Open this project in Android Studio.
2. Click *Run/Run 'app'*.
1. Click *Run/Run 'app'*.
To build from the command line:
1. Navigate to this directory in your terminal.
2. Run `./gradlew installDebug` (or `gradlew.bat installDebug` on Windows).
1. Run `./gradlew installDebug` (or `gradlew.bat installDebug` on Windows).
Screenshots
------------
## Screenshots
![screenshot](screenshot.png)
Support
--------
## Support
If you've found an error in these samples, please [file an
issue](https://github.com/android/ndk-samples/issues/new).
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by submitting a pull request
through GitHub. Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for more
details.
[android.mk]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/Android.mk#31
[build.gradle]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/build.gradle#L65
[c/c++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.0
[cmakelists.txt]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/CMakeLists.txt#L20
[gradle.properties]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/gradle.properties#L22
[headers]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/app.cpp#L23
[jsoncpp]: https://github.com/open-source-parsers/jsoncpp
[libraries]: https://github.com/android/ndk-samples/blob/main/prefab/prefab-dependency/app/src/main/cpp/CMakeLists.txt#L25
[prefab]: https://google.github.io/prefab/

View File

@@ -1,28 +1,31 @@
prefab-publishing
=================
# prefab-publishing
This sample shows how to export native libraries to an AAR using the [Prefab] format.
It builds a trivial library called `mylibrary` (libmylibrary.so), and packs the library
into mylibrary.aar. From here you could distribute the AAR via Maven or however
you distribute AARs.
This sample shows how to export native libraries to an AAR using the [Prefab]
format. It builds a trivial library called `mylibrary` (libmylibrary.so), and
packs the library into mylibrary.aar. From here you could distribute the AAR via
Maven or however you distribute AARs.
In order to export native libraries in an AAR with Android Gradle Plugin 4.1+,
make the following changes to your Android Library project's [build.gradle]:
* Enable the `prefabPublishing` build feature
- Enable the `prefabPublishing` build feature
```
android.buildFeatures.prefabPublishing true
```
* Declare the libraries and headers you wish to export in the `android.prefab`
- Declare the libraries and headers you wish to export in the `android.prefab`
block
```
android.prefab.mylibrary {
headers "src/main/cpp/include"
}
```
* (Optional) If the exported native modules are **not** used by the Kotlin/Java modules in this AAR,
you could avoid [the unnecessary duplication inside AAR]
- (Optional) If the exported native modules are **not** used by the Kotlin/Java
modules in this AAR, you could avoid [the unnecessary duplication inside AAR]
```
packagingOptions {
exclude("**/libmylibrary.so")
@@ -30,26 +33,16 @@ make the following changes to your Android Library project's [build.gradle]:
}
```
To learn how to use the generated AAR, refer to [the prefab-dependency sample]
in this repo; for the detailed documentation about Prefab in AGP, go to
[C/C++ dependencies] webpage.
To learn how to use the generated AAR, refer to [the prefab-dependency sample] in this repo;
for the detailed documentation about Prefab in AGP, go to [C/C++ dependencies] webpage.
## Pre-requisites
[Prefab]:https://google.github.io/prefab/
[build.gradle]:https://github.com/android/ndk-samples/blob/master/prefab/prefab-publishing/mylibrary/build.gradle#L64
[the prefab-dependency sample]:https://github.com/android/ndk-samples/tree/main/prefab/prefab-dependency
[the unnecessary duplication inside AAR]:https://issuetracker.google.com/issues/168777344#comment5
[C/C++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.1
- Android Gradle Plugin 4.1+
- The [Android NDK](https://developer.android.com/ndk/).
Pre-requisites
--------------
* Android Gradle Plugin 4.1+
* The [Android NDK](https://developer.android.com/ndk/).
Getting Started
---------------
## Getting Started
The C++ code in this sample is built with CMake, but the concepts demonstrated
here work identically when using ndk-build.
@@ -57,17 +50,22 @@ here work identically when using ndk-build.
To build:
1. Navigate to this directory in your terminal.
2. Run `./gradlew build` (or `gradlew.bat build` on Windows).
1. Run `./gradlew build` (or `gradlew.bat build` on Windows).
Note that there is no runnable application in this sample. The output is the
AAR.
Support
-------
## Support
If you've found an error in these samples, please [file an
issue](https://github.com/android/ndk-samples/issues/new).
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by submitting a pull request
through GitHub. Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for more
details.
[build.gradle]: https://github.com/android/ndk-samples/blob/master/prefab/prefab-publishing/mylibrary/build.gradle#L64
[c/c++ dependencies]: https://developer.android.com/studio/build/native-dependencies?buildsystem=cmake&agpversion=4.1
[prefab]: https://google.github.io/prefab/
[the prefab-dependency sample]: https://github.com/android/ndk-samples/tree/main/prefab/prefab-dependency
[the unnecessary duplication inside aar]: https://issuetracker.google.com/issues/168777344#comment5

View File

@@ -1,41 +1,49 @@
San Angeles
===========
San Angeles is an Android port of a demo that uses GLES C/API to render a procedural scene.
# San Angeles
See the original [README](app/src/main/cpp/README.txt) for more details about the original GLES port.
San Angeles is an Android port of a demo that uses GLES C/API to render a
procedural scene.
See the original [README](app/src/main/cpp/README.txt) for more details about
the original GLES port.
The sample demos:
- [Android Studio with CMake support](http://tools.android.com/tech-docs/external-c-builds)
- [ABI APK split](http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits#TOC-ABIs-Splits)
Pre-requisites
--------------
## Pre-requisites
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
See the original [licensing](app/src/main/jni/license.txt) information.

View File

@@ -1,56 +1,62 @@
Sensor-Graph
============
Sensor graph is a C++ Android sample that read current accelerometer values and draw them using OpenGL.
# Sensor-Graph
Sensor graph is a C++ Android sample that read current accelerometer values and
draw them using OpenGL.
It demonstrate usage of the following Native C++ API:
- [Sensors](http://developer.android.com/ndk/reference/group___sensor.html)
- [Assets](http://developer.android.com/ndk/reference/group___asset.html)
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.
Getting Started
---------------
## Getting Started
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open `android-ndk/sensor-graph` sample.
1. Open *File/Project Structure...*
1. Click *Download* or *Select NDK location*.
1. Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,59 +1,72 @@
Teapots
======
Teapots is an collection of Android C++ samples that uses a Teapot rendering to demostrate Android NDK platform features:
- classic-teapot: Rendering classic teapot mesh using GLES 2.0 API and [NativeActivity](http://developer.android.com/reference/android/app/NativeActivity.html).
- more-teapots: Rendering multiple instances of Classic Teapot with GLES 3.0 Instance Rendering
- choreographer-30fps: demonstrates multiple frame rate throttoling techniques based on API level using Choreographer API and EGL Android presentation time extension.
# Teapots
Teapots is an collection of Android C++ samples that uses a Teapot rendering to
demostrate Android NDK platform features:
- classic-teapot: Rendering classic teapot mesh using GLES 2.0 API and
[NativeActivity](http://developer.android.com/reference/android/app/NativeActivity.html).
- more-teapots: Rendering multiple instances of Classic Teapot with GLES 3.0
Instance Rendering
- choreographer-30fps: demonstrates multiple frame rate throttoling techniques
based on API level using Choreographer API and EGL Android presentation time
extension.
- textured-teapot: Rendering classic teapot plus textures
- image-decoder: Same as textured-teapot, except that texture decoding is done
with the ImageDecoder API introduced in Android 11 (Android NDK r21b)
This sample uses the new [Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds) with C++ support.
This sample uses the new
[Android Studio CMake plugin](http://tools.android.com/tech-docs/external-c-builds)
with C++ support.
## Pre-requisites
Pre-requisites
--------------
- Android Studio 4.0.0 with [NDK](https://developer.android.com/ndk/)
- Android [NDK 21.1+ installed](https://github.com/android/ndk-samples/wiki/Configure-NDK-Path)
- Android
[NDK 21.1+ installed](https://github.com/android/ndk-samples/wiki/Configure-NDK-Path)
## Getting Started
Getting Started
---------------
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/android/ndk-samples/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/android/ndk-samples/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/android/ndk-samples/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2020 Google LLC.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,12 +1,17 @@
image-decoder
==============
This sample demonstrates the [ImageDecoder](https://developer.android.com/ndk/guides/image-decoder) functionality added to Android 11:
# image-decoder
This sample demonstrates the
[ImageDecoder](https://developer.android.com/ndk/guides/image-decoder)
functionality added to Android 11:
- Texture files are decoded with AImageDecoder
- The rest of the code is the same as that of TexturedTeapot
This sample needs to be build with NDK 21.1 available from the canary channel, Android Studio 4.0+ would prompt you to install the needed NDK; in case you meet difficulties, check out
[NDK configuration documentation](https://github.com/android/ndk-samples/wiki/Configure-NDK-Path) to fix local issues.
- The rest of the code is the same as that of TexturedTeapot This sample needs
to be build with NDK 21.1 available from the canary channel, Android Studio
4.0+ would prompt you to install the needed NDK; in case you meet
difficulties, check out
[NDK configuration documentation](https://github.com/android/ndk-samples/wiki/Configure-NDK-Path)
to fix local issues.
## Screenshots
Screenshots
-----------
![screenshot](screenshot.png)

View File

@@ -1,6 +1,7 @@
textured-teapot
==============
# textured-teapot
This sample is a simple enhancement with a texture for classic-teapot
- The teapot vertex coordinators are part of the model files
- CPU side of the code for texturing is in TexturedTeapotRender class
- fragment shader simply textures in and blend
@@ -8,7 +9,6 @@ This sample is a simple enhancement with a texture for classic-teapot
- Renders plain, 2d textured, and cubemap textured teapots, refer to
TexturedTeapotRender::GetTextureType()
Screenshots
-----------
![screenshot](screenshot.png)
## Screenshots
![screenshot](screenshot.png)

View File

@@ -1,14 +1,14 @@
Unit Test
=========
# Unit Test
This Android sample shows how to write unit tests for native code with
[googletest](https://github.com/google/googletest), and run them on-device.
Writing unit tests
------------------
## Writing unit tests
This app has a very simple library containing a function to add two numbers.
[adder.h](app/src/main/cpp/adder.h):
```C++
#pragma once
@@ -16,13 +16,15 @@ int add(int a, int b);
```
[adder.cpp](app/src/main/cpp/adder.cpp):
```C++
#include "adder.h"
int add(int a, int b) { return a + b; }
```
[adder_test.cpp](app/src/main/cpp/adder_test.cpp) contains a unit test for this function:
[adder_test.cpp](app/src/main/cpp/adder_test.cpp) contains a unit test for this
function:
```C++
#include "adder.h"
@@ -32,10 +34,11 @@ int add(int a, int b) { return a + b; }
TEST(adder, adder) { EXPECT_EQ(3, add(1, 2)); }
```
Building and running the tests
------------------------------
## Building and running the tests
We need to add a library for the test to [CMakeLists.txt](app/src/main/cpp/CMakeLists.txt), which depends on googletest and junit-gtest:
We need to add a library for the test to
[CMakeLists.txt](app/src/main/cpp/CMakeLists.txt), which depends on googletest
and junit-gtest:
```cmake
find_package(googletest REQUIRED CONFIG)
@@ -52,7 +55,8 @@ target_link_libraries(app_tests
)
```
We need to add googletest and junit-gtest as dependencies in [app/build.gradle](app/build.gradle). Googletest uses prefab, so we enable that.
We need to add googletest and junit-gtest as dependencies in
[app/build.gradle](app/build.gradle). Googletest uses prefab, so we enable that.
```
build_features {
@@ -67,7 +71,8 @@ dependencies {
}
```
Finally, we need a wrapper in androidTest, [NativeTests.kt](app/src/androidTest/java/com/example/unittest/NativeTests.kt):
Finally, we need a wrapper in androidTest,
[NativeTests.kt](app/src/androidTest/java/com/example/unittest/NativeTests.kt):
```kotlin
package com.example.unittest
@@ -81,7 +86,8 @@ import org.junit.runner.RunWith
class NativeTests
```
You can run the test on a phone or emulator as described in the [Android developer documentation](https://developer.android.com/studio/test/test-in-android-studio).
You can run the test on a phone or emulator as described in the
[Android developer documentation](https://developer.android.com/studio/test/test-in-android-studio).
Try deliberately breaking the test, like this:
@@ -100,35 +106,37 @@ add(1,2)
Which is: 3
```
Screenshot
-----------
## Screenshot
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2022 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

View File

@@ -1,54 +1,61 @@
WEBP Samples
=============
Webp is an Android sample including a small app to demo usage of webp in [Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html)
# WEBP Samples
Webp is an Android sample including a small app to demo usage of webp in
[Native Activity](http://developer.android.com/reference/android/app/NativeActivity.html)\
view:
- rotate decoding 3 webp images and load them into on-screen buffer. Decoding is in its own thread
- rotate decoding 3 webp images and load them into on-screen buffer. Decoding is
in its own thread
This sample uses the new [Android Studio CMake plugin](https://developer.android.com/ndk/guides/cmake.html).
This sample uses the new
[Android Studio CMake plugin](https://developer.android.com/ndk/guides/cmake.html).
Pre-requisites
--------------
- Android Studio 3.0.0+ and android-ndk-r16
## Pre-requisites
Getting Started
---------------
1. Download Android Studio from [formal release](http://developer.android.com/sdk/index.html) or [canary](http://tools.android.com/download/studio/canary)
- Android Studio 3.0.0+ and android-ndk-r16
## Getting Started
1. Download Android Studio from
[formal release](http://developer.android.com/sdk/index.html) or
[canary](http://tools.android.com/download/studio/canary)
1. Launch Android Studio
1. Select "Import project (Eclipse ADT, Gradle,etc)"
1. Browse into downloaded sample directory, select webp/build.gradle
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.
Screenshots
-----------
## Screenshots
![screenshot](screenshot.png)
Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).
## Support
Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
If you've found an error in these samples, please
[file an issue](https://github.com/googlesamples/android-ndk/issues/new).
Patches are encouraged, and may be submitted by
[forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see
[CONTRIBUTING.md](../CONTRIBUTING.md) for more details.
- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Android Tools Feedbacks](http://tools.android.com/feedback)
License
-------
## License
Copyright 2015 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.