Skip to content

Commit

Permalink
[Android] Fix using system libraries in Android apps (#14145)
Browse files Browse the repository at this point in the history
- Starting from API 31, using `uses-native-library` is required if we
  want to open system library:
  https://developer.android.com/about/versions/12/reference/compat-framework-changes#enforce_native_shared_library_dependencies

  We should specify OpenCL library in `user-native-library` in all
  applications where OpenCL backend might be used.

- Updated README files and describe how to fix synchronization issues
  in Android Studio.
  • Loading branch information
echuraev authored Mar 2, 2023
1 parent 908dc8f commit 25f4d06
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions apps/android_camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,13 @@ Run uninstall first:
```bash
$ANDROID_HOME/platform-tools/adb uninstall ml.apache.tvm.android.androidcamerademo
```
### Troubleshooting

If you build the application in Android Studio and see error similar to this one:
```
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
> Minimum supported Gradle version is 7.5. Current version is 7.4. If using the gradle wrapper, try editing the distributionUrl in /Users/echuraev/Workspace/OctoML/tvm_android_test/apps/android_deploy/gradle/wrapper/gradle-wrapper.properties to gradle-7.5-all.zip
```
Run project syncing `File -> Sync Project with Gradle Files`. It should sync the
project and create gradle-wrapper files.
3 changes: 3 additions & 0 deletions apps/android_camera/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,MissingApplicationIcon">
<uses-native-library
android:name="libOpenCL.so"
android:required="false"/>
<activity
android:name="org.apache.tvm.android.androidcamerademo.MainActivity"
android:exported="true"
Expand Down
2 changes: 1 addition & 1 deletion apps/android_camera/models/prepare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def main(model_str, output_path):
raise RuntimeError("Require environment variable TVM_NDK_CC")
models_path = Path().absolute().parent.joinpath("app/src/main/assets/models/")
if not models_path.exists():
models_path.mkdir()
models_path.mkdir(parents=True)
models = {
"mobilenet_v2": models_path.joinpath("mobilenet_v2"),
"resnet18_v1": models_path.joinpath("resnet18_v1"),
Expand Down
11 changes: 11 additions & 0 deletions apps/android_deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ Copied these compiled model deploy_lib.so, deploy_graph.json and deploy_param.pa
Install compiled android application on phone and enjoy the image classifier demo using extraction model

You can define your own TVM operators and deploy via this demo application on your Android device to find the most optimized TVM schedule.

### Troubleshooting

If you build the application in Android Studio and see error similar to this one:
```
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
> Minimum supported Gradle version is 7.5. Current version is 7.4. If using the gradle wrapper, try editing the distributionUrl in /Users/echuraev/Workspace/OctoML/tvm_android_test/apps/android_deploy/gradle/wrapper/gradle-wrapper.properties to gradle-7.5-all.zip
```
Run project syncing `File -> Sync Project with Gradle Files`. It should sync the
project and create gradle-wrapper files.
3 changes: 3 additions & 0 deletions apps/android_deploy/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ under the License.
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<uses-native-library
android:name="libOpenCL.so"
android:required="false"/>
<activity
android:name="org.apache.tvm.android.demo.MainActivity"
android:theme="@style/AppTheme.NoActionBar"
Expand Down
11 changes: 11 additions & 0 deletions apps/android_rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,14 @@ Run GPU(Vulkan Flavor) test ...
```

You can define your own TVM operators and test via this RPC app on your Android device to find the most optimized TVM schedule.

### Troubleshooting

If you build the application in Android Studio and see error similar to this one:
```
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
> Minimum supported Gradle version is 7.5. Current version is 7.4. If using the gradle wrapper, try editing the distributionUrl in /Users/echuraev/Workspace/OctoML/tvm_android_test/apps/android_deploy/gradle/wrapper/gradle-wrapper.properties to gradle-7.5-all.zip
```
Run project syncing `File -> Sync Project with Gradle Files`. It should sync the
project and create gradle-wrapper files.
3 changes: 3 additions & 0 deletions apps/android_rpc/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ under the License.
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher">
<uses-native-library
android:name="libOpenCL.so"
android:required="false"/>
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar"
Expand Down

0 comments on commit 25f4d06

Please sign in to comment.