Consolidate developer documentation in mdBook docs (#3115)

This commit is contained in:
Bart Louwers
2025-01-06 20:16:49 +01:00
committed by GitHub
parent 660f78c583
commit c7e6b0c796
14 changed files with 321 additions and 132 deletions

View File

@@ -0,0 +1,66 @@
# MapLibre Android Developer Guide
These instructions are for developers interested in making code-level contributions to MapLibre Native for Android.
## Getting the source
Clone the git repository and pull in submodules:
```bash
git clone git@github.com:maplibre/maplibre-native.git
cd maplibre-native
git submodule update --init --recursive
cd platform/android
```
## Requirements
[Android Studio](https://developer.android.com/studio) needs to be installed.
Open the `platform/android` directory to get started.
## Setting an API Key
_The test application (used for development purposes) uses MapTiler vector tiles, which require a MapTiler account and API key._
With the first Gradle invocation, Gradle will take the value of the `MLN_API_KEY` environment variable and save it to `MapLibreAndroidTestApp/src/main/res/values/developer-config.xml`. If the environment variable wasn't set, you can edit `developer-config.xml` manually and add your API key to the `api_key` resource.
## Running the TestApp
Run the configuration for the `MapLibreAndroidTestApp` module and select a device or emulator to deploy on.
<p align="left">
<img src="https://github.com/maplibre/maplibre-native/assets/649392/5494925e-8cbb-4d5d-8033-8a2f141ede3c" alt="Android TestApp menu" width="15%"> <img src="https://github.com/maplibre/maplibre-native/assets/649392/f169db51-615d-4fca-b297-ac6197bec674" alt="Android TestApp showing Demotiles" width="15%">
</p>
## Kotlin
All new code should be written in [Kotlin](https://kotlinlang.org/).
## Style Checking
To check Kotlin style, we use [ktlint](https://pinterest.github.io/ktlint/). This linter is based on the [official Kotlin coding conventions](https://kotlinlang.org/docs/coding-conventions.html). We intergrate with it using the [kotlinder](https://github.com/jeremymailen/kotlinter-gradle) Gradle plugin.
To check the style of all Kotlin source files, use:
```
$ ./gradlew checkStyle
```
To format all Kotlin source files, use:
```
$ ./gradlew formatKotlin
```
## Benchmarks in Pull Request
To run the benchmarks (for Android) include the following line on a PR comment:
```
!benchmark android
```
## Profiling
See [Tracy Profiling](/profiling/tracy-profiling.md) to understand how Tracy can be used for profiling.

View File

@@ -0,0 +1,49 @@
# Documentation for MapLibre Android
## API Documentation
We use Dokka for the MapLibre Android API documentation. The live documentation site can be found [here](https://maplibre.org/maplibre-native/android/api/).
## Examples Documentation
The documentation site with examples uses MkDocs along with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/). You can check out the site [here](https://maplibre.org/maplibre-native/android/examples/).
### Building
To build the Examples Documentation you need to have Docker installed.
From `platform/android`, run:
```
make mkdocs
```
Next, visit [`http://localhost:8000/maplibre-native/android/examples/`](http://localhost:8000/maplibre-native/android/examples/).
### Snippets
We use [a Markdown extension for snippets](https://facelessuser.github.io/pymdown-extensions/extensions/snippets/#snippet-sections). This way code can be referenced instead of copy pasted into the documentation. This avoids code examples from becoming out of date or failing to compile. The syntax is as follows:
````kotlin
// --8<-- [start:fun]
fun double(x: Int): Int {
return 2 * x
}
// --8<-- [end:fun]
````
Next, you'll be able to reference that piece of code in Markdown like so:
```
--8<-- "example.kt:fun"
```
Where `example.kt` is the path to the file.
### Static Assets
Static assets are ideally uploaded to the [MapLibre Native S3 Bucket](https://maplibre-native.s3.eu-central-1.amazonaws.com/index.html#android-documentation-resources/).
Please open an issue with the ARN of your AWS account to get upload privileges.
You can use the macro `{{ s3_url("filename.example") }}` which will use a CDN instead of linking to the S3 bucket directly.

View File

@@ -0,0 +1,91 @@
# MapLibre Android Tests
## Render Tests
To run the render tests for Android, run the configuration for the `androidRenderTest.app` module.
### Filtering Render Tests
You can filter the tests to run by passing a flag to the file `platform/android/src/test/render_test_runner.cpp`:
```cpp
std::vector<std::string> arguments = {..., "-f", "background-color/literal"};
```
### Viewing the Results
Once the application quits, use the Device Explorer to navigate to `/data/data/org.maplibre.render_test_runner/files`.
<img width="980" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/0dc42d4a-6221-46b6-8352-1eb24d466e91">
Double click `android-render-test-runner-style.html`. Right click on the opened tab and select _Open In > Browser_. You should see that a single render test passed.
<img width="801" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/33e88999-7787-492f-afd9-f5a3e3fd61f7">
Alternatively to download (and open) the results from the command line, use:
```
adb shell "run-as org.maplibre.render_test_runner cat files/metrics/android-render-test-runner-style.html" > android-render-test-runner-style.html
open android-render-test-runner-style.html
```
### Updating the Render Tests
Now let's edit `metrics/integration/render-tests/background-color/literal/style.json`, change this line:
```
"background-color": "red"
```
to
```
"background-color": "yellow"
```
We need to make sure that the new `data.zip` with the data for the render tests is installed on the device. You can use the following commands:
```
tar chf render-test/android/app/src/main/assets/data.zip --format=zip --files-from=render-test/android/app/src/main/assets/to_zip.txt
adb push render-test/android/app/src/main/assets/data.zip /data/local/tmp/data.zip
adb shell chmod 777 /data/local/tmp/data.zip
adb shell "run-as org.maplibre.render_test_runner unzip -o /data/local/tmp/data.zip -d files"
```
Rerun the render test app and reload the Device Explorer. When you re-open the HTML file with the results you should now see a failing test:
<img width="685" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/303ad75a-cf74-4b8c-927c-c9bd59a79de4">
Now download the `actual.png` in `metrics/integration/render-tests/background-color/literal` with the Device Explorer. Replace the corresponding `expected.png` on your local file system. Upload the new render test data again and run the test app once more.
<img width="800" alt="image" src="https://github.com/maplibre/maplibre-native/assets/649392/04734c6a-9cf1-489a-b9bb-8d857581261c">
Of we don't want to commit this change. But know you can add and debug (Android) render tests.
## Instrumentation Tests
To run the instrumentation tests, choose the "Instrumentation Tests" run configuration.
Your device needs remain unlocked for the duration of the tests.
## C++ Unit Tests
There is a separate Gradle project that contains a test app which runs the C++ Unit Tests. It does not depend on the Android platform implementations.
You can find the project in `test/android.` You can open this project in Android Studio and run the C++ Tests on an Android device or Simulator.
To run a particular set of tests you can modify the `--gtest_filter` flag in `platform/android/src/test/test_runner.cpp`. See the [GoogleTest documentation](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) for details how to use this flag.
### AWS Device Farm
The instrumentation tests and C++ unit tests are running on AWS Device Farm. To see the results and the logs, go to:
[https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/20687d72-0e46-403e-8f03-0941850665bc/runs](https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/20687d72-0e46-403e-8f03-0941850665bc/runs).
Use the following login details (this is a read-only account):
| | |
|------------|------------|
| Alias | `maplibre` |
| Username | `maplibre` |
| Password | `maplibre` |