From 30209a6c053a9a5cbe2bd3a897b4d199a8f903b2 Mon Sep 17 00:00:00 2001 From: Hansong Zhang <107070759+kirklandsign@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:52:09 -0700 Subject: [PATCH 1/5] Add qnn deps to LlamaDemo gradle --- examples/demo-apps/android/LlamaDemo/app/build.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts index 893b1ee4784..9ce615b5870 100644 --- a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts +++ b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts @@ -11,6 +11,8 @@ plugins { id("org.jetbrains.kotlin.android") } +def qnnVersion = System.properties['qnnVersion'] + android { namespace = "com.example.executorchllamademo" compileSdk = 34 @@ -61,6 +63,9 @@ dependencies { implementation("com.google.android.material:material:1.12.0") implementation("androidx.activity:activity:1.9.0") implementation("org.json:json:20250107") + if (qnnVersion) { + implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion" + } testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") From 72149012db6d3ed8d4424ba936f8bcecf6de468e Mon Sep 17 00:00:00 2001 From: Hansong Zhang <107070759+kirklandsign@users.noreply.github.com> Date: Wed, 3 Sep 2025 10:21:55 -0700 Subject: [PATCH 2/5] Update qualcomm_README.md --- .../android/LlamaDemo/docs/delegates/qualcomm_README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md index 68aed7000c8..5616bae55f3 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md @@ -212,6 +212,9 @@ sh examples/demo-apps/android/LlamaDemo/setup-with-qnn.sh This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them into AAR, and copies it to the app. Note: If you are building the Android app mentioned in the next section on a separate machine (i.e. MacOS but building and exporting for QNN backend on Linux), make sure you copy the aar file generated from setup-with-qnn script to "examples/demo-apps/android/LlamaDemo/app/libs" before building the Android app. +6. Set up the correct QNN version in gradle rule +In app/build.gradle.kts, find the line `def qnnVersion = System.properties['qnnVersion']` and `implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion"`. The gradle variable `qnnVersion` needs to be defined as the QNN SDK version (ex. 2.28). You can replace the line `def qnnVersion = System.properties['qnnVersion']` with `def qnnVersion = '2.28'` locally, or you can add `-DqnnVersion=2.28` when you trigger gradle build. + ## Run the Android Demo App From 8140a4392cba88fe1da2432d7c9cee81e632569d Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Wed, 3 Sep 2025 10:40:53 -0700 Subject: [PATCH 3/5] Fix gradle --- examples/demo-apps/android/LlamaDemo/app/build.gradle.kts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts index 9ce615b5870..9710cd5e93b 100644 --- a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts +++ b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts @@ -11,7 +11,8 @@ plugins { id("org.jetbrains.kotlin.android") } -def qnnVersion = System.properties['qnnVersion'] +val qnnVersion: String? = project.findProperty("qnnVersion") as? String + android { namespace = "com.example.executorchllamademo" @@ -63,8 +64,8 @@ dependencies { implementation("com.google.android.material:material:1.12.0") implementation("androidx.activity:activity:1.9.0") implementation("org.json:json:20250107") - if (qnnVersion) { - implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion" + if (!qnnVersion.isNullOrEmpty()) { + implementation("com.qualcomm.qti:qnn-runtime:$qnnVersion") } testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") From c0504e2912395c40549554071a4ac6f8550ddc26 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Wed, 3 Sep 2025 10:42:45 -0700 Subject: [PATCH 4/5] Fix readme --- .../android/LlamaDemo/docs/delegates/qualcomm_README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md index 5616bae55f3..cd0a453e6b6 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md @@ -213,8 +213,7 @@ This is running the shell script which configures the required core ExecuTorch, Note: If you are building the Android app mentioned in the next section on a separate machine (i.e. MacOS but building and exporting for QNN backend on Linux), make sure you copy the aar file generated from setup-with-qnn script to "examples/demo-apps/android/LlamaDemo/app/libs" before building the Android app. 6. Set up the correct QNN version in gradle rule -In app/build.gradle.kts, find the line `def qnnVersion = System.properties['qnnVersion']` and `implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion"`. The gradle variable `qnnVersion` needs to be defined as the QNN SDK version (ex. 2.28). You can replace the line `def qnnVersion = System.properties['qnnVersion']` with `def qnnVersion = '2.28'` locally, or you can add `-DqnnVersion=2.28` when you trigger gradle build. - +Currently, the gralde rule searches for the property `qnnVersion`. When this variable is defined, it will add QNN runtime library to the dependency. To use it, append the string `qnnVersion=` (ex. `qnnVersion=2.28.0`) to the end of the `gradle.properties` file. ## Run the Android Demo App From 4018825cc574716397b7d838a4a7baeebf088beb Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Wed, 3 Sep 2025 10:48:39 -0700 Subject: [PATCH 5/5] bump --- examples/demo-apps/android/LlamaDemo/app/build.gradle.kts | 1 - .../android/LlamaDemo/docs/delegates/qualcomm_README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts index 9710cd5e93b..19cfda847db 100644 --- a/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts +++ b/examples/demo-apps/android/LlamaDemo/app/build.gradle.kts @@ -13,7 +13,6 @@ plugins { val qnnVersion: String? = project.findProperty("qnnVersion") as? String - android { namespace = "com.example.executorchllamademo" compileSdk = 34 diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md index cd0a453e6b6..c1a93d02f93 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md @@ -213,7 +213,7 @@ This is running the shell script which configures the required core ExecuTorch, Note: If you are building the Android app mentioned in the next section on a separate machine (i.e. MacOS but building and exporting for QNN backend on Linux), make sure you copy the aar file generated from setup-with-qnn script to "examples/demo-apps/android/LlamaDemo/app/libs" before building the Android app. 6. Set up the correct QNN version in gradle rule -Currently, the gralde rule searches for the property `qnnVersion`. When this variable is defined, it will add QNN runtime library to the dependency. To use it, append the string `qnnVersion=` (ex. `qnnVersion=2.28.0`) to the end of the `gradle.properties` file. +Currently, the gralde rule searches for the property `qnnVersion`. When this variable is defined, it will add QNN runtime library to the dependency. To use it, append the string `qnnVersion=` (ex. `qnnVersion=2.37.0`) to the end of the `gradle.properties` file. ## Run the Android Demo App