diff --git a/examples/DemoRunner/Builds/Android/app/build.gradle b/examples/DemoRunner/Builds/Android/app/build.gradle index 493b015fb6..16e333032f 100644 --- a/examples/DemoRunner/Builds/Android/app/build.gradle +++ b/examples/DemoRunner/Builds/Android/app/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'com.android.application' +def ndkVersionString = "25.2.9519653" + android { compileSdkVersion 33 - ndkVersion "25.2.9519653" + ndkVersion ndkVersionString namespace "com.rmsl.jucedemorunner" externalNativeBuild { cmake { diff --git a/extras/AudioPerformanceTest/Builds/Android/app/build.gradle b/extras/AudioPerformanceTest/Builds/Android/app/build.gradle index 7274fd3640..6039614ceb 100644 --- a/extras/AudioPerformanceTest/Builds/Android/app/build.gradle +++ b/extras/AudioPerformanceTest/Builds/Android/app/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'com.android.application' +def ndkVersionString = "25.2.9519653" + android { compileSdkVersion 33 - ndkVersion "25.2.9519653" + ndkVersion ndkVersionString namespace "com.juce.audioperformancetest" externalNativeBuild { cmake { diff --git a/extras/AudioPluginHost/Builds/Android/app/build.gradle b/extras/AudioPluginHost/Builds/Android/app/build.gradle index a422c1cf15..01d5e346a9 100644 --- a/extras/AudioPluginHost/Builds/Android/app/build.gradle +++ b/extras/AudioPluginHost/Builds/Android/app/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'com.android.application' +def ndkVersionString = "25.2.9519653" + android { compileSdkVersion 33 - ndkVersion "25.2.9519653" + ndkVersion ndkVersionString namespace "com.juce.audiopluginhost" externalNativeBuild { cmake { diff --git a/extras/NetworkGraphicsDemo/Builds/Android/app/build.gradle b/extras/NetworkGraphicsDemo/Builds/Android/app/build.gradle index 6bbc057bcf..65fd525773 100644 --- a/extras/NetworkGraphicsDemo/Builds/Android/app/build.gradle +++ b/extras/NetworkGraphicsDemo/Builds/Android/app/build.gradle @@ -1,8 +1,10 @@ apply plugin: 'com.android.application' +def ndkVersionString = "25.2.9519653" + android { compileSdkVersion 33 - ndkVersion "25.2.9519653" + ndkVersion ndkVersionString namespace "com.juce.networkgraphicsdemo" externalNativeBuild { cmake { diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h index 1919acd5fe..5fc45e7df3 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Android.h @@ -105,7 +105,7 @@ public: androidReadMediaVideoPermission, androidExternalWritePermission, androidInAppBillingPermission, androidVibratePermission, androidOtherPermissions, androidPushNotifications, androidEnableRemoteNotifications, androidRemoteNotificationsConfigFile, androidEnableContentSharing, androidKeyStore, - androidKeyStorePass, androidKeyAlias, androidKeyAliasPass, gradleVersion, gradleToolchain, androidPluginVersion; + androidKeyStorePass, androidKeyAlias, androidKeyAliasPass, gradleVersion, gradleToolchain, gradleClangTidy, androidPluginVersion; //============================================================================== AndroidProjectExporter (Project& p, const ValueTree& t) @@ -151,6 +151,7 @@ public: androidKeyAliasPass (settings, Ids::androidKeyAliasPass, getUndoManager(), "android"), gradleVersion (settings, Ids::gradleVersion, getUndoManager(), "7.5.1"), gradleToolchain (settings, Ids::gradleToolchain, getUndoManager(), "clang"), + gradleClangTidy (settings, Ids::gradleClangTidy, getUndoManager(), false), androidPluginVersion (settings, Ids::androidPluginVersion, getUndoManager(), "7.3.0"), AndroidExecutable (getAppSettings().getStoredPath (Ids::androidStudioExePath, TargetOS::getThisOS()).get().toString()) { @@ -171,6 +172,9 @@ public: { "clang", "gcc" }, { "clang", "gcc" }), "The toolchain that gradle should invoke for NDK compilation (variable model.android.ndk.tooclhain in app/build.gradle)"); + + props.add (new ChoicePropertyComponent (gradleClangTidy, "Use Clang-Tidy"), + "If enabled and the toolchain is clang this will run clang-tidy when compiling."); } //============================================================================== @@ -680,10 +684,22 @@ private: mo << "apply plugin: 'com.android." << (isLibrary() ? "library" : "application") << "'" << newLine << newLine; + // CMake 3.22 will fail to build Android projects that set ANDROID_ARM_MODE unless NDK 24+ is used + mo << "def ndkVersionString = \"25.2.9519653\"" << newLine << newLine; + + if (gradleClangTidy.get() && gradleToolchain.get().toString() == "clang") + mo << "Properties properties = new Properties()" << newLine + << "properties.load(project.rootProject.file(\"local.properties\").newDataInputStream())" << newLine + << "def llvmDir = \"${properties.getProperty('sdk.dir')}/ndk/${ndkVersionString}/toolchains/llvm\"" << newLine + << "def clangTidySearch = fileTree(llvmDir).filter { file -> file.name.matches('^clang-tidy(.exe)?$') }" << newLine + << "if (clangTidySearch.size() != 1) {" << newLine + << " throw new GradleException(\"Could not locate a unique clang-tidy in ${llvmDir}\")" << newLine + << "}" << newLine + << "def clangTidy = clangTidySearch.getSingleFile().getAbsolutePath()" << newLine << newLine; + mo << "android {" << newLine; mo << " compileSdkVersion " << static_cast (androidTargetSDK.get()) << newLine; - // CMake 3.22 will fail to build Android projects that set ANDROID_ARM_MODE unless NDK 24+ is used - mo << " ndkVersion \"25.2.9519653\"" << newLine; + mo << " ndkVersion ndkVersionString" << newLine; mo << " namespace " << project.getBundleIdentifierString().toLowerCase().quoted() << newLine; mo << " externalNativeBuild {" << newLine; mo << " cmake {" << newLine; @@ -1488,6 +1504,9 @@ private: cmakeArgs.add ("\"-DANDROID_ARM_MODE=arm\""); cmakeArgs.add ("\"-DANDROID_ARM_NEON=TRUE\""); + if (isClang && gradleClangTidy.get()) + cmakeArgs.add ("\"-DCMAKE_CXX_CLANG_TIDY=${clangTidy}\""); + auto cppStandard = [this] { auto projectStandard = project.getCppStandardString(); diff --git a/extras/Projucer/Source/Utility/Helpers/jucer_PresetIDs.h b/extras/Projucer/Source/Utility/Helpers/jucer_PresetIDs.h index 590e645624..a95cf1c364 100644 --- a/extras/Projucer/Source/Utility/Helpers/jucer_PresetIDs.h +++ b/extras/Projucer/Source/Utility/Helpers/jucer_PresetIDs.h @@ -283,6 +283,7 @@ namespace Ids const Identifier androidPluginVersion ("gradleWrapperVersion"); // old name is very confusing, but we need to remain backward compatible DECLARE_ID (gradleToolchain); DECLARE_ID (gradleToolchainVersion); + DECLARE_ID (gradleClangTidy); DECLARE_ID (linuxExtraPkgConfig); DECLARE_ID (font); DECLARE_ID (colour);