Blog Infos
Author
Published
Topics
, , , ,
Published
Here are some useful tips

This article is about the problems faced while importing Android project with C++ or NDK code.

First and foremost, download NDK and CMake from SDK Tools as shown in the screenshot below.

As you can see, NDK (Side by side) and CMake is already installed in my Android Studio.

Issue 1:

After importing an Android project (not only C++ or NDK code), you may get the following error.

Error:

Your build is currently configured to use Gradle 8.0. Cannot sync the project. We recommend upgrading to Gradle version 8.9. The minimum compatible Gradle version is 8.5. We recommend upgrading to Gradle version 8.9.

The minimum compatible Gradle version is 8.5.

Possible solutions:
— Upgrade to Gradle 8.9 and re-sync
— Upgrade to Gradle 8.5 and re-sync

Solution:

For the above issue, solution is simple.

Upgrade Android Gradle Plugin (AGP) to the required version (8.5 or 8.9)

Once the solution is applied, you should see the updated version in gradle-wrapper.properties file like below

distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip

 

Issue 2:

While building Android project with C++ or NDK code, you may get the following error.

Error:

:app debug:arm64-v8a failed to configure C/C++

Solution:

To solve the above issue, we need to check and update the CMake version in app’s build.gradle like below.

externalNativeBuild {
    cmake {
        path "src/main/cpp/Android/CMakeLists.txt"
        version "3.31.5"
    }
}

In my case, CMake version was 3.10.2. I upgraded it to 3.31.5 and that solved the issue.

Issue 3: (Runtime issue)

After solving Issue 1 and Issue 2, we may get runtime issues

Error:

org.gradle.workers.WorkerExecutionException: There were multiple failures while executing work items

Caused by: org.gradle.tooling.BuildException: Failed to process:

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process:

After seeing DexArchiveBuilderException, one thing that might come in mind is about enabling MultiDex but that is not the issue here.

Solution:

Upgrading JavaVersion

From

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

To

compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

worked for me.

Issue 4:

After solving Issue 3, we may get the following error.

Error:

Execution failed for task ‘:app:compileDebugJavaWithJavac’.
> Could not resolve all files for configuration ‘:app:androidJdkImage’.

Solution:

After searching for the solution in StackOverFlow, got the below solution.

Update plugin version of our app in project’s build.gradle.

In my case, updating

From

plugins {
id 'com.android.application' version '8.0.0' apply false
}

To

plugins {
    id 'com.android.application' version '8.3.2' apply false
}

solved the issue.

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

,

Meta-programming with K2 compiler plugins

Let’s see what’s possible with plugins using the new K2 compiler, FIR. This live demo session will go through possible use cases that reduce boilerplate code and make your code safer.
Watch Video

Meta-programming with K2 compiler plugins

Tadeas Kriz
Senior Kotlin Developer
Touchlab

Meta-programming with K2 compiler plugins

Tadeas Kriz
Senior Kotlin Develo ...
Touchlab

Meta-programming with K2 compiler plugins

Tadeas Kriz
Senior Kotlin Developer
Touchlab

Jobs

No results found.

Another tip:

Directly applying solution of Issue 4 i.e updating plugin of our app in project’s build.gradle solved Issue 3(which means we can skip solution of upgrading JavaVersion). This was found out later.

 . . .

Thanks for reading this article. If you like this post, Please give a clap (👏).

Also, if you like to support me through
https://buymeacoffee.com/dilipchandar, please do.

Let’s connect on LinkedIn https://www.linkedin.com/in/dilip-chandar-97570158?

This article is previously published on proandroiddev.com.

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Using annotations in Kotlin has some nuances that are useful to know
READ MORE
blog
One of the latest trends in UI design is blurring the background content behind the foreground elements. This creates a sense of depth, transparency, and focus,…
READ MORE
blog
Now that Android Studio Iguana is out and stable, I wanted to write about…
READ MORE
blog
The suspension capability is the most essential feature upon which all other Kotlin Coroutines…
READ MORE
Menu