I notice that the later versions of gradle have a means to exclude resources, however I have not seen any examples supporting this where we specify .jni.srcDirs, which unselectively includes everything under each .srcDir path.
Does anyone know of a way to specify certain subdirectories to exclude, for NDK?
What about excluding individual files by extension?
My only alternative seems to be to explicitly list files that are used.
P.S. I don't want to use Android.mk; if possible I would prefer to stick with Gradle's automation.
At least for the present, this doesn't seem to be possible through gradle.
What I've done for now is to delete unwanted files (example sources) from the source folders (then had git ignore those deletions so it doesn't try to check in changes to the project's submodule dependencies). This way I can keep the repos the same but still have Android Studio / gradle not process those unwanted files.
Of course, if you cut gradle out of the picture altogether, you can do whatever you like with your makefile, including solving this problem.
Related
I'm trying to load an opencv example into Android Studio.
When I clone the repository, one of the files is "build.gradle.in".
Android studio normally uses "build.gradle" files, without the ".in" extension. (See
build.gradle in the project vs. build.gradle in the app
"android camera calibration"
https://github.com/rpng/android-camera-calibration/blob/master/app/build.gradle
etc.
).
What is a "build.gradle.in" file?
Do I need to do something with it?
Do I need to tell Android Studio to do something with it, and if so, how?
(I tried to search for "build.gradle.in" in my favorite search engine, but I get a bunch of irrelevant documents talking about placing the file "build.gradle" "in" some folder or another).
(Disclaimer: This is only a partial answer as I cannot tell what to do with that file)
From the contents of the repository (in particular android_gradle_projects.cmake) it appears to be a template file used as input (therefore .in) to create a final build.gradle with dynamic content.
See e.g. line 35 of android_gradle_projects.cmake:
configure_file("${OpenCV_SOURCE_DIR}/samples/android/build.gradle.in" "${ANDROID_BUILD_BASE_DIR}/build.gradle" #ONLY)
In combination with e.g. line 100 of build.gradle.in:
minSdkVersion #ANDROID_MIN_SDK_VERSION#
configure_file copies a file with modifications, e.g. replacing variables in the form of #VAR#.
I didn't manage to figure out how to use the build.gradle.in file, but you can download the openCV android sdk, which will contain the same sample projects already configured for gradle.
From a previous question a new one have arisen. I want to include 2 native TFS project libraries stored in two different folders, dependant from each other in my Android Studio project (stored in another folder). If i not specify "../my_lib_path/libFile.h" instead of simply the "libFile.h" i get the error the file is not found. But i dont want to change all includes since it is a TFS project and there are lots of file contained in the libraries!
Your help is highly appreciated!
Add the given directories to those the compiler uses to search for include files. Relative paths are interpreted as relative to the current source directory. So you have to specify "../my_lib_path/libFile.h", that means you need to change all includes, otherwise it will not work.
#Andy Li-MSFT is absolutely right! Though what worked for me in a similar project now was to set a different relative CMakeLists.txt path in the app .gradle file outside the specific Android Studio Project directory:
externalNativeBuild {
cmake {
path "../../whatever_path/my_C_files/CMakeLists.txt"
}
}
After that i was able to compile my C sources flawlessly without changing the include paths of the C project!
I've defined a CMakeLists.txt file for my project which works correctly.
I use the CMake GUI for generating a Visual Studio Project, and I ask to build the binaries (CMAke cache and other stuff) in the folder Build which is in the same folder where CMakeLists.txt is.
I was able to specify where the executable and the libraries have to be created.
Is there a way to specify also where the Visual Studio Solution file has to be created? I would like to have it in the root directory, but at the same time I don't want to have also all the other files that CMake creates in the Build directory.
CMake creates the Project I defined in CMakeLists.txt but also two other projects: ALL_BUILD and ZERO_CHECK. What's their utility?
I was able to avoid the creation of ZERO_CHECK by using the command set_property(GLOBAL PROPERTY USE_FOLDERS On).
Is there a way for avoiding also the creation of ALL_BUILD?
It seems you only switched to CMake very recently, as exactly those questions also popped into my head when I first started using CMake. Let's address them in the order you posted them:
I use the CMake GUI for generating a Visual Studio Project, and I ask
to build the binaries (CMAke cache and other stuff) in the folder
Build which is in the same folder where CMakeLists.txt is.
Don't. Always do an out-of-source build with CMake. I know, it feels weird when you do it the first time, but trust me: Once you get used to it, you'll never want to go back.
Besides the fact that using source control becomes so much more convenient when code and build files are properly separated, this also allows to build separate distinct build configurations from the same source tree at the same time.
Is there a way to specify also where the Visual Studio Solution file has to be created?
You really shouldn't care.
I see why you do feel that you need full control over how the solution and project files get created, but you really don't. Simply specify the target for the solution as the origin of your out-of-source build and forget about all the other files that are generated. You don't need to worry, and you don't want to worry - this is exactly the kind of stuff that CMake is supposed to take care of for you.
Ask yourself: What would you gain if you could handpick the location of every project file? Nothing, because chances are, you will never touch them anyways. CMake is your sole master now...
CMake creates the Project I defined in CMakeLists.txt but also two
other projects: ALL_BUILD and ZERO_CHECK. What's their utility? I was
able to avoid the creation of ZERO_CHECK by using the command
set_property(GLOBAL PROPERTY USE_FOLDERS On). Is there a way for
avoiding also the creation of ALL_BUILD?
Again, you really shouldn't care. CMake defines a couple of dummy projects which are very useful for certain internal voodoo that you don't want to worry about. They look weird at first, but you'll get used to their sight faster than you think. Just don't try to throw them out, as it won't work properly.
If their sight really annoys you that much, consider moving them to a folder inside the solution so that you don't have to look at them all the time.
Bottom line: CMake feels different than a handcrafted VS solution in a couple of ways. This takes some getting used to, but is ultimately a much less painful experience than one might fear.
You don't always have a choice about what your environment requires. Visual Studio's GitHub integration requires that the solution file exists in source control and is at the root of the source tree. It's a documented limitation.
The best I was able to come up with is adding this bit to CMakeList.txt:
# The solution file isn't generated until after this script finishes,
# which means that:
# - it might not exist (if this is the first run)
# - you need to run cmake twice to ensure any new solution was copied
set(sln_binpath ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.sln)
if(EXISTS ${sln_binpath})
# Load solution file from bin-dir and change the relative references to
# project files so that the in memory copy is as if it had been built in
# the source dir.
file(RELATIVE_PATH prefix
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
file(READ ${sln_binpath} sln_content)
string(REGEX REPLACE
"\"([^\"]+).vcxproj\""
"\"${prefix}/\\1.vcxproj\""
sln_content
"${sln_content}")
# Compare the updated contents with the existing source path sln, if it
# exists and is the same we don't want to disturb VS by touching it.
set(sln_srcpath ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.sln)
set(old_content "")
if(EXISTS ${sln_srcpath})
file(READ ${sln_srcpath} old_content)
endif()
if(NOT old_content STREQUAL sln_content)
file(WRITE ${sln_srcpath} ${sln_content})
endif()
endif()
What would be helpful is if cmake had a way to run post generation scripts, but I couldn't find one.
Other ideas that didn't work out:
wrap cmake inside a script that does the same thing, but:
telling users to run a seperate script isn't simpler than saying to run cmake twice. Especially since needing to run cmake twice isn't a foreign concept.
put it in a pre-build step, but
building is common and changing the build is rare
changing the solution from builds inside the IDE makes it do... things
use add_subdirectory because that's suppose to finish first
it appeared to make the vcxproj's immediately, but not the sln until later, but I didn't try as hard because this adds a bunch of additional clutter I didn't want - so maybe this can be made to work
Dropped a ton of files on a project, now I need to clean it up by deleting the files that are not being used. To optimize the app from loading all the necessary files.
I need to find and delete them. Thanks!
As far as I know it is not possible without additional software. Some times ago a used NDepend (demo is available) for this job. Worked very well. I'm sure ReSharper can also do it.
You may just try parsing the csproj file as Xml to figure out what files are being used and cross check with files on the disk to get the list of files to be deleted.
I have a large set of include directories for my solution, and want to exclude one of them for a single project in the solution, how can I do this?
There is no way to exclude an include for a single project in the solution (after conversation with folks at MSDN). The best workaround is to not inherit from solution for that one specific project, and to define its includes at the project level, without the directory that was causing problems.