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
Release: 2024-11-27 06:57:10
Original
629 people have browsed it

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"
        }
    }
}
Copy after login

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"
    }
}
Copy after login
  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)
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template