diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_AndroidStudio.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_AndroidStudio.h index 91efe9ae83..4fe6975faa 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_AndroidStudio.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_AndroidStudio.h @@ -336,7 +336,7 @@ private: struct GradleHeaderIncludePath : public GradleStatement { GradleHeaderIncludePath (const String& path) - : GradleStatement ("cppFlags.add(\"-I" + sanitisePath (path) + "\".toString())") {} + : GradleStatement ("cppFlags.add(\"-I${project.rootDir}/" + sanitisePath (path) + "\".toString())") {} }; struct GradleLibrarySearchPath : public GradleStatement @@ -563,21 +563,11 @@ private: ndkSettings->add ("toolchain", toolchain); ndkSettings->add ("stl", isClang ? "c++_static" : "gnustl_static"); - ndkSettings->addChildObject (getNdkJuceExtraProperties()); - addAllNdkCompilerSettings (ndkSettings); return ndkSettings; } - GradleObject* getNdkJuceExtraProperties() const - { - auto ext = new GradleObject ("ext"); - ext->add ("juceRootDir", "${project.rootDir}/../../../../"); - ext->add ("juceModuleDir", "${juceRootDir}/modules"); - return ext; - } - void addAllNdkCompilerSettings (GradleObject* ndk) const { addNdkCppFlags (ndk); @@ -608,16 +598,33 @@ private: void addNdkHeaderIncludePaths (GradleObject* ndk) const { - const char* basicJucePaths[] = { "${project.rootDir}/app", "${ext.juceRootDir}", "${ext.juceModuleDir}", nullptr }; - StringArray includePaths (basicJucePaths); + StringArray includePaths; - includePaths.add (sanitisePath (project.getProjectFolder().getFullPathName() + "/Source/")); - includePaths.add (sanitisePath (project.getProjectFolder().getFullPathName() + "/../../JUCE/modules/")); + for (const auto& cppFile : getAllCppFilesToBeIncludedWithPath()) + includePaths.addIfNotAlreadyThere (cppFile.getParentDirectory().toUnixStyle()); for (const auto& path : includePaths) ndk->add (path); } + Array getAllCppFilesToBeIncludedWithPath() const + { + Array cppFiles; + + struct NeedsToBeIncludedWithPathPredicate + { + bool operator() (const Project::Item& projectItem) const + { + return projectItem.shouldBeAddedToTargetProject() && ! projectItem.isModuleCode(); + } + }; + + for (const auto& group : getAllGroups()) + findAllProjectItemsWithPredicate (group, cppFiles, NeedsToBeIncludedWithPathPredicate()); + + return cppFiles; + } + void addNdkLinkerFlags (GradleObject* ndk) const { const auto linkerFlags = StringArray::fromTokens (getExtraLinkerFlagsString(), " ", ""); @@ -700,7 +707,7 @@ private: ndkSettings->add ("-O" + config.getGCCOptimisationFlag()); - for (const auto& path : config.getHeaderSearchPaths()) + for (const auto& path : getHeaderSearchPaths (config)) ndkSettings->add (path); for (const auto& path : config.getLibrarySearchPaths()) @@ -718,6 +725,14 @@ private: buildConfig->addChildObject (ndkSettings); } + StringArray getHeaderSearchPaths (const BuildConfiguration& config) const + { + StringArray paths (extraSearchPaths); + paths.addArray (config.getHeaderSearchPaths()); + paths = getCleanedStringArray (paths); + return paths; + } + GradleObject* getAndroidSigningConfigs() const { auto releaseConfig = new GradleObject ("create(\"releaseConfig\")"); @@ -806,12 +821,6 @@ private: writeXmlOrThrow (*manifest, folder.getChildFile ("app/src/main/AndroidManifest.xml"), "utf-8", 100, true); } - //============================================================================== - struct ShouldBeAddedToProjectPredicate - { - bool operator() (const Project::Item& projectItem) const { return projectItem.shouldBeAddedToTargetProject(); } - }; - //============================================================================== const File androidStudioExecutable;