Home >Backend Development >C++ >How Can I Exclude Files from LOCAL_SRC_FILES in the NDK Gradle DSL?

How Can I Exclude Files from LOCAL_SRC_FILES in the NDK Gradle DSL?

DDD
DDDOriginal
2024-11-27 06:57:10631browse

How Can I Exclude Files from LOCAL_SRC_FILES in the NDK Gradle DSL?

Bypassing LOCAL_SRC_FILES in NDK DSL With Exclusion Patterns

Question:

Can LOCAL_SRC_FILES be defined within an NDK DSL block in Gradle?

Original Answer (Deprecated):

Currently, this feature is not supported by the Gradle plugin. Consider using the traditional Android.mk file.

Updated Answer:

With the release of Gradle plugin 0.4.0, this is now possible using exclusion patterns.

android.sources {
    main {
        jni.source {
            srcDirs = ["~/srcs/jni"]
            exclude "**/win.cpp"
        }
    }
}

Alternative Solution with Static Library:

To exclude files from NDK builds without using LOCAL_SRC_FILES, a different approach can be taken.

  1. Create a static library containing the excluded files.
  2. Modify build.gradle to depend on the static library:
model {
    android.ndk {
        moduleName = "hello-jni"
        abiFilters += "$appAbi".toString()
        ldFlags += "$staticLib".toString()
        ldLibs += "log"
        cppFlags += "-std=c++11"
    }
}
  1. Define the static library in Android.mk:
LOCAL_MODULE    := staticLib
LOCAL_SRC_FILES := HelloJni.cpp

LOCAL_CPPFLAGS += -std=c++11

include $(BUILD_STATIC_LIBRARY)

This approach effectively excludes the specified files from regular NDK builds and ensures the necessary symbols are available for debugging.

Note: Remember to trigger a "Build/Clean" after modifying the exclusion settings.

The above is the detailed content of How Can I Exclude Files from LOCAL_SRC_FILES in the NDK Gradle DSL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn