The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1278 lines
56KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class AndroidProjectExporter : public ProjectExporter
  18. {
  19. public:
  20. //==============================================================================
  21. bool isXcode() const override { return false; }
  22. bool isVisualStudio() const override { return false; }
  23. bool isCodeBlocks() const override { return false; }
  24. bool isMakefile() const override { return false; }
  25. bool isAndroidStudio() const override { return true; }
  26. bool isAndroid() const override { return true; }
  27. bool isWindows() const override { return false; }
  28. bool isLinux() const override { return false; }
  29. bool isOSX() const override { return false; }
  30. bool isiOS() const override { return false; }
  31. bool usesMMFiles() const override { return false; }
  32. bool canCopeWithDuplicateFiles() override { return false; }
  33. bool supportsUserDefinedConfigurations() const override { return true; }
  34. bool supportsTargetType (ProjectType::Target::Type type) const override
  35. {
  36. switch (type)
  37. {
  38. case ProjectType::Target::GUIApp:
  39. case ProjectType::Target::StaticLibrary:
  40. case ProjectType::Target::StandalonePlugIn:
  41. return true;
  42. default:
  43. break;
  44. }
  45. return false;
  46. }
  47. //==============================================================================
  48. void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
  49. {
  50. // no-op.
  51. }
  52. //==============================================================================
  53. void createExporterProperties (PropertyListBuilder& props) override
  54. {
  55. createBaseExporterProperties (props);
  56. createToolchainExporterProperties (props);
  57. createManifestExporterProperties (props);
  58. createLibraryModuleExporterProperties (props);
  59. createCodeSigningExporterProperties (props);
  60. createOtherExporterProperties (props);
  61. }
  62. static const char* getName() { return "Android"; }
  63. static const char* getValueTreeTypeName() { return "ANDROIDSTUDIO"; }
  64. static AndroidProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  65. {
  66. if (settings.hasType (getValueTreeTypeName()))
  67. return new AndroidProjectExporter (project, settings);
  68. return nullptr;
  69. }
  70. //==============================================================================
  71. CachedValue<String> androidScreenOrientation, androidActivityClass, androidActivitySubClassName,
  72. androidVersionCode, androidMinimumSDK, androidTheme,
  73. androidSharedLibraries, androidStaticLibraries;
  74. CachedValue<bool> androidInternetNeeded, androidMicNeeded, androidBluetoothNeeded;
  75. CachedValue<String> androidOtherPermissions;
  76. CachedValue<String> androidKeyStore, androidKeyStorePass, androidKeyAlias, androidKeyAliasPass;
  77. CachedValue<String> gradleVersion, androidPluginVersion, gradleToolchain, buildToolsVersion;
  78. //==============================================================================
  79. AndroidProjectExporter (Project& p, const ValueTree& t)
  80. : ProjectExporter (p, t),
  81. androidScreenOrientation (settings, Ids::androidScreenOrientation, nullptr, "unspecified"),
  82. androidActivityClass (settings, Ids::androidActivityClass, nullptr, createDefaultClassName()),
  83. androidActivitySubClassName (settings, Ids::androidActivitySubClassName, nullptr),
  84. androidVersionCode (settings, Ids::androidVersionCode, nullptr, "1"),
  85. androidMinimumSDK (settings, Ids::androidMinimumSDK, nullptr, "10"),
  86. androidTheme (settings, Ids::androidTheme, nullptr),
  87. androidSharedLibraries (settings, Ids::androidSharedLibraries, nullptr, ""),
  88. androidStaticLibraries (settings, Ids::androidStaticLibraries, nullptr, ""),
  89. androidInternetNeeded (settings, Ids::androidInternetNeeded, nullptr, true),
  90. androidMicNeeded (settings, Ids::microphonePermissionNeeded, nullptr, false),
  91. androidBluetoothNeeded (settings, Ids::androidBluetoothNeeded, nullptr, true),
  92. androidOtherPermissions (settings, Ids::androidOtherPermissions, nullptr),
  93. androidKeyStore (settings, Ids::androidKeyStore, nullptr, "${user.home}/.android/debug.keystore"),
  94. androidKeyStorePass (settings, Ids::androidKeyStorePass, nullptr, "android"),
  95. androidKeyAlias (settings, Ids::androidKeyAlias, nullptr, "androiddebugkey"),
  96. androidKeyAliasPass (settings, Ids::androidKeyAliasPass, nullptr, "android"),
  97. gradleVersion (settings, Ids::gradleVersion, nullptr, "2.14.1"),
  98. androidPluginVersion (settings, Ids::androidPluginVersion, nullptr, "2.2.3"),
  99. gradleToolchain (settings, Ids::gradleToolchain, nullptr, "clang"),
  100. buildToolsVersion (settings, Ids::buildToolsVersion, nullptr, "25.0.2"),
  101. AndroidExecutable (findAndroidExecutable())
  102. {
  103. initialiseDependencyPathValues();
  104. name = getName();
  105. if (getTargetLocationString().isEmpty())
  106. getTargetLocationValue() = getDefaultBuildsRootFolder() + "Android";
  107. }
  108. //==============================================================================
  109. void createToolchainExporterProperties (PropertyListBuilder& props)
  110. {
  111. props.add (new TextWithDefaultPropertyComponent<String> (gradleVersion, "gradle version", 32),
  112. "The version of gradle that is used to build this app (2.14.1 is fine for JUCE)");
  113. props.add (new TextWithDefaultPropertyComponent<String> (androidPluginVersion, "android plug-in version", 32),
  114. "The version of the android build plugin for gradle that is used to build this app");
  115. static const char* toolchains[] = { "clang", "gcc", nullptr };
  116. props.add (new ChoicePropertyComponent (gradleToolchain.getPropertyAsValue(), "NDK Toolchain", StringArray (toolchains), Array<var> (toolchains)),
  117. "The toolchain that gradle should invoke for NDK compilation (variable model.android.ndk.tooclhain in app/build.gradle)");
  118. props.add (new TextWithDefaultPropertyComponent<String> (buildToolsVersion, "Android build tools version", 32),
  119. "The Android build tools version that should use to build this app");
  120. }
  121. void createLibraryModuleExporterProperties (PropertyListBuilder& props)
  122. {
  123. props.add (new TextPropertyComponent (androidStaticLibraries.getPropertyAsValue(), "Import static library modules", 8192, true),
  124. "Comma or whitespace delimited list of static libraries (.a) defined in NDK_MODULE_PATH.");
  125. props.add (new TextPropertyComponent (androidSharedLibraries.getPropertyAsValue(), "Import shared library modules", 8192, true),
  126. "Comma or whitespace delimited list of shared libraries (.so) defined in NDK_MODULE_PATH.");
  127. }
  128. //==============================================================================
  129. bool canLaunchProject() override
  130. {
  131. return AndroidExecutable.exists();
  132. }
  133. bool launchProject() override
  134. {
  135. if (! AndroidExecutable.exists())
  136. {
  137. jassertfalse;
  138. return false;
  139. }
  140. const File targetFolder (getTargetFolder());
  141. // we have to surround the path with extra quotes, otherwise Android Studio
  142. // will choke if there are any space characters in the path.
  143. return AndroidExecutable.startAsProcess ("\"" + targetFolder.getFullPathName() + "\"");
  144. }
  145. //==============================================================================
  146. void create (const OwnedArray<LibraryModule>& modules) const override
  147. {
  148. const File targetFolder (getTargetFolder());
  149. const File appFolder (targetFolder.getChildFile (isLibrary() ? "lib" : "app"));
  150. removeOldFiles (targetFolder);
  151. {
  152. const String package (getActivityClassPackage());
  153. const String path (package.replaceCharacter ('.', File::separator));
  154. const File javaTarget (targetFolder.getChildFile ("app/src/main/java").getChildFile (path));
  155. if (! isLibrary())
  156. copyActivityJavaFiles (modules, javaTarget, package);
  157. }
  158. writeFile (targetFolder, "settings.gradle", isLibrary() ? "include ':lib'" : "include ':app'");
  159. writeFile (targetFolder, "build.gradle", getProjectBuildGradleFileContent());
  160. writeFile (appFolder, "build.gradle", getAppBuildGradleFileContent());
  161. writeFile (targetFolder, "local.properties", getLocalPropertiesFileContent());
  162. writeFile (targetFolder, "gradle/wrapper/gradle-wrapper.properties", getGradleWrapperPropertiesFileContent());
  163. writeBinaryFile (targetFolder, "gradle/wrapper/LICENSE-for-gradlewrapper.txt", BinaryData::LICENSE, BinaryData::LICENSESize);
  164. writeBinaryFile (targetFolder, "gradle/wrapper/gradle-wrapper.jar", BinaryData::gradlewrapper_jar, BinaryData::gradlewrapper_jarSize);
  165. writeBinaryFile (targetFolder, "gradlew", BinaryData::gradlew, BinaryData::gradlewSize);
  166. writeBinaryFile (targetFolder, "gradlew.bat", BinaryData::gradlew_bat, BinaryData::gradlew_batSize);
  167. targetFolder.getChildFile ("gradlew").setExecutePermission (true);
  168. writeAndroidManifest (appFolder);
  169. if (! isLibrary())
  170. {
  171. writeStringsXML (targetFolder);
  172. writeAppIcons (targetFolder);
  173. }
  174. writeCmakeFile (appFolder.getChildFile ("CMakeLists.txt"));
  175. }
  176. void removeOldFiles (const File& targetFolder) const
  177. {
  178. targetFolder.getChildFile ("app/src").deleteRecursively();
  179. targetFolder.getChildFile ("app/build").deleteRecursively();
  180. targetFolder.getChildFile ("app/build.gradle").deleteFile();
  181. targetFolder.getChildFile ("gradle").deleteRecursively();
  182. targetFolder.getChildFile ("local.properties").deleteFile();
  183. targetFolder.getChildFile ("settings.gradle").deleteFile();
  184. }
  185. void writeFile (const File& gradleProjectFolder, const String& filePath, const String& fileContent) const
  186. {
  187. MemoryOutputStream outStream;
  188. outStream << fileContent;
  189. overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
  190. }
  191. void writeBinaryFile (const File& gradleProjectFolder, const String& filePath, const char* binaryData, const int binarySize) const
  192. {
  193. MemoryOutputStream outStream;
  194. outStream.write (binaryData, static_cast<size_t> (binarySize));
  195. overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
  196. }
  197. //==============================================================================
  198. static File findAndroidExecutable()
  199. {
  200. #if JUCE_WINDOWS
  201. const File defaultInstallation ("C:\\Program Files\\Android\\Android Studio\\bin");
  202. if (defaultInstallation.exists())
  203. {
  204. {
  205. const File studio64 = defaultInstallation.getChildFile ("studio64.exe");
  206. if (studio64.existsAsFile())
  207. return studio64;
  208. }
  209. {
  210. const File studio = defaultInstallation.getChildFile ("studio.exe");
  211. if (studio.existsAsFile())
  212. return studio;
  213. }
  214. }
  215. #elif JUCE_MAC
  216. const File defaultInstallation ("/Applications/Android Studio.app");
  217. if (defaultInstallation.exists())
  218. return defaultInstallation;
  219. #endif
  220. return File();
  221. }
  222. protected:
  223. //==============================================================================
  224. class AndroidBuildConfiguration : public BuildConfiguration
  225. {
  226. public:
  227. AndroidBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
  228. : BuildConfiguration (p, settings, e)
  229. {
  230. if (getArchitectures().isEmpty())
  231. {
  232. if (isDebug())
  233. getArchitecturesValue() = "armeabi x86";
  234. else
  235. getArchitecturesValue() = "";
  236. }
  237. }
  238. Value getArchitecturesValue() { return getValue (Ids::androidArchitectures); }
  239. String getArchitectures() const { return config [Ids::androidArchitectures]; }
  240. var getDefaultOptimisationLevel() const override { return var ((int) (isDebug() ? gccO0 : gccO3)); }
  241. void createConfigProperties (PropertyListBuilder& props) override
  242. {
  243. addGCCOptimisationProperty (props);
  244. props.add (new TextPropertyComponent (getArchitecturesValue(), "Architectures", 256, false),
  245. "A list of the ARM architectures to build (for a fat binary). Leave empty to build for all possible android archiftectures.");
  246. }
  247. String getProductFlavourNameIdentifier() const
  248. {
  249. return getName().toLowerCase().replaceCharacter (L' ', L'_') + String ("_");
  250. }
  251. String getProductFlavourCMakeIdentifier() const
  252. {
  253. return getName().toUpperCase().replaceCharacter (L' ', L'_');
  254. }
  255. };
  256. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
  257. {
  258. return new AndroidBuildConfiguration (project, v, *this);
  259. }
  260. private:
  261. void writeCmakeFile (const File& file) const
  262. {
  263. MemoryOutputStream mo;
  264. mo << "# Automatically generated makefile, created by the Projucer" << newLine
  265. << "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
  266. << newLine;
  267. mo << "cmake_minimum_required(VERSION 3.4.1)" << newLine << newLine;
  268. if (! isLibrary())
  269. mo << "SET(BINARY_NAME \"juce_jni\")" << newLine << newLine;
  270. {
  271. StringArray projectDefines (getEscapedPreprocessorDefs (getProjectPreprocessorDefs()));
  272. if (projectDefines.size() > 0)
  273. mo << "add_definitions(" << projectDefines.joinIntoString (" ") << ")" << newLine << newLine;
  274. }
  275. writeCmakePathLines (mo, "", "include_directories( AFTER", extraSearchPaths);
  276. const String& cfgExtraLinkerFlags = getExtraLinkerFlagsString();
  277. if (cfgExtraLinkerFlags.isNotEmpty())
  278. {
  279. mo << "SET( JUCE_LDFLAGS \"" << cfgExtraLinkerFlags.replace ("\"", "\\\"") << "\")" << newLine;
  280. mo << "SET( CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} ${JUCE_LDFLAGS}\")" << newLine << newLine;
  281. }
  282. if (getNumConfigurations() > 0)
  283. {
  284. bool first = true;
  285. for (ConstConfigIterator config (*this); config.next();)
  286. {
  287. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  288. const StringArray& libSearchPaths = cfg.getLibrarySearchPaths();
  289. const StringPairArray& cfgDefines = getConfigPreprocessorDefs (cfg);
  290. const StringArray& cfgHeaderPaths = cfg.getHeaderSearchPaths();
  291. const StringArray& cfgLibraryPaths = cfg.getLibrarySearchPaths();
  292. if (! isLibrary() && libSearchPaths.size() == 0 && cfgDefines.size() == 0
  293. && cfgHeaderPaths.size() == 0 && cfgLibraryPaths.size() == 0)
  294. continue;
  295. mo << (first ? "IF" : "ELSEIF") << "(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg.getProductFlavourCMakeIdentifier() <<"\")" << newLine;
  296. if (isLibrary())
  297. mo << " SET(BINARY_NAME \"" << getNativeModuleBinaryName (cfg) << "\")" << newLine;
  298. writeCmakePathLines (mo, " ", "link_directories(", libSearchPaths);
  299. if (cfgDefines.size() > 0)
  300. mo << " add_definitions(" << getEscapedPreprocessorDefs (cfgDefines).joinIntoString (" ") << ")" << newLine;
  301. writeCmakePathLines (mo, " ", "include_directories( AFTER", cfgHeaderPaths);
  302. writeCmakePathLines (mo, " ", "link_directories(", cfgLibraryPaths);
  303. first = false;
  304. }
  305. if (! first)
  306. {
  307. ProjectExporter::BuildConfiguration::Ptr config (getConfiguration(0));
  308. if (config)
  309. {
  310. if (const auto* cfg = dynamic_cast<const AndroidBuildConfiguration*> (config.get()))
  311. {
  312. mo << "ELSE(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine;
  313. mo << " MESSAGE( FATAL_ERROR \"No matching build-configuration found.\" )" << newLine;
  314. mo << "ENDIF(JUCE_BUILD_CONFIGFURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine << newLine;
  315. }
  316. }
  317. }
  318. }
  319. Array<RelativePath> excludeFromBuild;
  320. mo << "add_library( ${BINARY_NAME}" << newLine;
  321. mo << newLine;
  322. mo << " SHARED" << newLine;
  323. mo << newLine;
  324. addCompileUnits (mo, excludeFromBuild);
  325. mo << ")" << newLine << newLine;
  326. if (excludeFromBuild.size() > 0)
  327. {
  328. for (auto& exclude : excludeFromBuild)
  329. mo << "set_source_files_properties(\"" << exclude.toUnixStyle() << "\" PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
  330. mo << newLine;
  331. }
  332. const StringArray& libraries = getProjectLibraries();
  333. if (libraries.size() > 0)
  334. {
  335. for (auto& lib : libraries)
  336. mo << "find_library(" << lib.toLowerCase().replaceCharacter (L' ', L'_') << " \"" << lib << "\")" << newLine;
  337. mo << newLine;
  338. }
  339. mo << "target_link_libraries( ${BINARY_NAME}";
  340. if (libraries.size() > 0)
  341. {
  342. mo << newLine << newLine;
  343. for (auto& lib : libraries)
  344. mo << " ${" << lib.toLowerCase().replaceCharacter (L' ', L'_') << "}" << newLine;
  345. }
  346. mo << ")" << newLine;
  347. overwriteFileIfDifferentOrThrow (file, mo);
  348. }
  349. //==============================================================================
  350. String getProjectBuildGradleFileContent() const
  351. {
  352. MemoryOutputStream mo;
  353. mo << "buildscript {" << newLine;
  354. mo << " repositories {" << newLine;
  355. mo << " jcenter()" << newLine;
  356. mo << " }" << newLine;
  357. mo << " dependencies {" << newLine;
  358. mo << " classpath 'com.android.tools.build:gradle:" << androidPluginVersion.get() << "'" << newLine;
  359. mo << " }" << newLine;
  360. mo << "}" << newLine;
  361. mo << "" << newLine;
  362. mo << "allprojects {" << newLine;
  363. mo << " repositories {" << newLine;
  364. mo << " jcenter()" << newLine;
  365. mo << " }" << newLine;
  366. mo << "}" << newLine;
  367. return mo.toString();
  368. }
  369. //==============================================================================
  370. String getAppBuildGradleFileContent () const
  371. {
  372. MemoryOutputStream mo;
  373. mo << "apply plugin: 'com.android." << (isLibrary() ? "library" : "application") << "'" << newLine << newLine;
  374. mo << "android {" << newLine;
  375. mo << " compileSdkVersion " << androidMinimumSDK.get().getIntValue() << newLine;
  376. mo << " buildToolsVersion \"" << buildToolsVersion.get() << "\"" << newLine;
  377. mo << " externalNativeBuild {" << newLine;
  378. mo << " cmake {" << newLine;
  379. mo << " path \"CMakeLists.txt\"" << newLine;
  380. mo << " }" << newLine;
  381. mo << " }" << newLine;
  382. mo << getAndroidSigningConfig() << newLine;
  383. mo << getAndroidDefaultConfig() << newLine;
  384. mo << getAndroidBuildTypes() << newLine;
  385. mo << getAndroidProductFlavours() << newLine;
  386. mo << getAndroidVariantFilter() << newLine;
  387. mo << "}" << newLine;
  388. return mo.toString();
  389. }
  390. String getAndroidProductFlavours() const
  391. {
  392. MemoryOutputStream mo;
  393. mo << " productFlavors {" << newLine;
  394. for (ConstConfigIterator config (*this); config.next();)
  395. {
  396. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  397. mo << " " << cfg.getProductFlavourNameIdentifier() << " {" << newLine;
  398. if (cfg.getArchitectures().isNotEmpty())
  399. {
  400. mo << " ndk {" << newLine;
  401. mo << " abiFilters " << toGradleList (StringArray::fromTokens (cfg.getArchitectures(), " ", "")) << newLine;
  402. mo << " }" << newLine;
  403. }
  404. mo << " externalNativeBuild {" << newLine;
  405. mo << " cmake {" << newLine;
  406. mo << " arguments \"-DJUCE_BUILD_CONFIGFURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\"" << newLine;
  407. mo << " cFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  408. mo << " cppFlags \"-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
  409. mo << " }" << newLine;
  410. mo << " }" << newLine;
  411. mo << " }" << newLine;
  412. }
  413. mo << " }" << newLine;
  414. return mo.toString();
  415. }
  416. String getAndroidSigningConfig() const
  417. {
  418. MemoryOutputStream mo;
  419. String keyStoreFilePath = androidKeyStore.get().replace ("${user.home}", "${System.properties['user.home']}")
  420. .replace ("/", "${File.separator}");
  421. mo << " signingConfigs {" << newLine;
  422. mo << " release {" << newLine;
  423. mo << " storeFile file(\"" << keyStoreFilePath << "\")" << newLine;
  424. mo << " storePassword \"" << androidKeyStorePass.get() << "\"" << newLine;
  425. mo << " keyAlias \"" << androidKeyAlias.get() << "\"" << newLine;
  426. mo << " keyPassword \"" << androidKeyAliasPass.get() << "\"" << newLine;
  427. mo << " storeType \"jks\"" << newLine;
  428. mo << " }" << newLine;
  429. mo << " }" << newLine;
  430. return mo.toString();
  431. }
  432. String getAndroidDefaultConfig() const
  433. {
  434. const String bundleIdentifier = project.getBundleIdentifier().toString().toLowerCase();
  435. const StringArray& cmakeDefs = getCmakeDefinitions();
  436. const StringArray& cFlags = getProjectCompilerFlags();
  437. const StringArray& cxxFlags = getProjectCxxCompilerFlags();
  438. const int minSdkVersion = androidMinimumSDK.get().getIntValue();
  439. MemoryOutputStream mo;
  440. mo << " defaultConfig {" << newLine;
  441. if (! isLibrary())
  442. mo << " applicationId \"" << bundleIdentifier << "\"" << newLine;
  443. mo << " minSdkVersion " << minSdkVersion << newLine;
  444. mo << " targetSdkVersion " << minSdkVersion << newLine;
  445. mo << " externalNativeBuild {" << newLine;
  446. mo << " cmake {" << newLine;
  447. mo << " arguments " << cmakeDefs.joinIntoString (", ") << newLine;
  448. if (cFlags.size() > 0)
  449. mo << " cFlags " << cFlags.joinIntoString (", ") << newLine;
  450. if (cxxFlags.size() > 0)
  451. mo << " cppFlags " << cxxFlags.joinIntoString (", ") << newLine;
  452. mo << " }" << newLine;
  453. mo << " }" << newLine;
  454. mo << " }" << newLine;
  455. return mo.toString();
  456. }
  457. String getAndroidBuildTypes() const
  458. {
  459. MemoryOutputStream mo;
  460. mo << " buildTypes {" << newLine;
  461. int numDebugConfigs = 0;
  462. const int numConfigs = getNumConfigurations();
  463. for (int i = 0; i < numConfigs; ++i)
  464. {
  465. auto config = getConfiguration(i);
  466. if (config->isDebug()) numDebugConfigs++;
  467. if (numDebugConfigs > 1 || ((numConfigs - numDebugConfigs) > 1))
  468. continue;
  469. mo << " " << (config->isDebug() ? "debug" : "release") << " {" << newLine;
  470. mo << " initWith " << (config->isDebug() ? "debug" : "release") << newLine;
  471. mo << " debuggable " << (config->isDebug() ? "true" : "false") << newLine;
  472. mo << " jniDebuggable " << (config->isDebug() ? "true" : "false") << newLine;
  473. if (! config->isDebug())
  474. mo << " signingConfig signingConfigs.release" << newLine;
  475. mo << " }" << newLine;
  476. }
  477. mo << " }" << newLine;
  478. return mo.toString();
  479. }
  480. String getAndroidVariantFilter() const
  481. {
  482. MemoryOutputStream mo;
  483. mo << " variantFilter { variant ->" << newLine;
  484. mo << " def names = variant.flavors*.name" << newLine;
  485. for (ConstConfigIterator config (*this); config.next();)
  486. {
  487. const auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
  488. mo << " if (names.contains (\"" << cfg.getProductFlavourNameIdentifier() << "\")" << newLine;
  489. mo << " && variant.buildType.name != \"" << (cfg.isDebug() ? "debug" : "release") << "\") {" << newLine;
  490. mo << " setIgnore(true)" << newLine;
  491. mo << " }" << newLine;
  492. }
  493. mo << " }" << newLine;
  494. return mo.toString();
  495. }
  496. //==============================================================================
  497. String getLocalPropertiesFileContent() const
  498. {
  499. String props;
  500. props << "ndk.dir=" << sanitisePath (ndkPath.toString()) << newLine
  501. << "sdk.dir=" << sanitisePath (sdkPath.toString()) << newLine;
  502. return props;
  503. }
  504. String getGradleWrapperPropertiesFileContent() const
  505. {
  506. String props;
  507. props << "distributionUrl=https\\://services.gradle.org/distributions/gradle-"
  508. << gradleVersion.get() << "-all.zip";
  509. return props;
  510. }
  511. //==============================================================================
  512. void createBaseExporterProperties (PropertyListBuilder& props)
  513. {
  514. static const char* orientations[] = { "Portrait and Landscape", "Portrait", "Landscape", nullptr };
  515. static const char* orientationValues[] = { "unspecified", "portrait", "landscape", nullptr };
  516. props.add (new ChoicePropertyComponent (androidScreenOrientation.getPropertyAsValue(), "Screen orientation", StringArray (orientations), Array<var> (orientationValues)),
  517. "The screen orientations that this app should support");
  518. props.add (new TextWithDefaultPropertyComponent<String> (androidActivityClass, "Android Activity class name", 256),
  519. "The full java class name to use for the app's Activity class.");
  520. props.add (new TextPropertyComponent (androidActivitySubClassName.getPropertyAsValue(), "Android Activity sub-class name", 256, false),
  521. "If not empty, specifies the Android Activity class name stored in the app's manifest. "
  522. "Use this if you would like to use your own Android Activity sub-class.");
  523. props.add (new TextWithDefaultPropertyComponent<String> (androidVersionCode, "Android Version Code", 32),
  524. "An integer value that represents the version of the application code, relative to other versions.");
  525. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), sdkPath, "Android SDK Path"),
  526. "The path to the Android SDK folder on the target build machine");
  527. props.add (new DependencyPathPropertyComponent (project.getFile().getParentDirectory(), ndkPath, "Android NDK Path"),
  528. "The path to the Android NDK folder on the target build machine");
  529. props.add (new TextWithDefaultPropertyComponent<String> (androidMinimumSDK, "Minimum SDK version", 32),
  530. "The number of the minimum version of the Android SDK that the app requires");
  531. }
  532. //==============================================================================
  533. void createManifestExporterProperties (PropertyListBuilder& props)
  534. {
  535. props.add (new BooleanPropertyComponent (androidInternetNeeded.getPropertyAsValue(), "Internet Access", "Specify internet access permission in the manifest"),
  536. "If enabled, this will set the android.permission.INTERNET flag in the manifest.");
  537. props.add (new BooleanPropertyComponent (androidMicNeeded.getPropertyAsValue(), "Audio Input Required", "Specify audio record permission in the manifest"),
  538. "If enabled, this will set the android.permission.RECORD_AUDIO flag in the manifest.");
  539. props.add (new BooleanPropertyComponent (androidBluetoothNeeded.getPropertyAsValue(), "Bluetooth permissions Required", "Specify bluetooth permission (required for Bluetooth MIDI)"),
  540. "If enabled, this will set the android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN flag in the manifest. This is required for Bluetooth MIDI on Android.");
  541. props.add (new TextPropertyComponent (androidOtherPermissions.getPropertyAsValue(), "Custom permissions", 2048, false),
  542. "A space-separated list of other permission flags that should be added to the manifest.");
  543. }
  544. //==============================================================================
  545. void createCodeSigningExporterProperties (PropertyListBuilder& props)
  546. {
  547. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStore, "Key Signing: key.store", 2048),
  548. "The key.store value, used when signing the release package.");
  549. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyStorePass, "Key Signing: key.store.password", 2048),
  550. "The key.store password, used when signing the release package.");
  551. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAlias, "Key Signing: key.alias", 2048),
  552. "The key.alias value, used when signing the release package.");
  553. props.add (new TextWithDefaultPropertyComponent<String> (androidKeyAliasPass, "Key Signing: key.alias.password", 2048),
  554. "The key.alias password, used when signing the release package.");
  555. }
  556. //==============================================================================
  557. void createOtherExporterProperties (PropertyListBuilder& props)
  558. {
  559. props.add (new TextPropertyComponent (androidTheme.getPropertyAsValue(), "Android Theme", 256, false),
  560. "E.g. @android:style/Theme.NoTitleBar or leave blank for default");
  561. }
  562. //==============================================================================
  563. String createDefaultClassName() const
  564. {
  565. String s (project.getBundleIdentifier().toString().toLowerCase());
  566. if (s.length() > 5
  567. && s.containsChar ('.')
  568. && s.containsOnly ("abcdefghijklmnopqrstuvwxyz_.")
  569. && ! s.startsWithChar ('.'))
  570. {
  571. if (! s.endsWithChar ('.'))
  572. s << ".";
  573. }
  574. else
  575. {
  576. s = "com.yourcompany.";
  577. }
  578. return s + CodeHelpers::makeValidIdentifier (project.getProjectFilenameRoot(), false, true, false);
  579. }
  580. void initialiseDependencyPathValues()
  581. {
  582. sdkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidSDKPath),
  583. Ids::androidSDKPath, TargetOS::getThisOS())));
  584. ndkPath.referTo (Value (new DependencyPathValueSource (getSetting (Ids::androidNDKPath),
  585. Ids::androidNDKPath, TargetOS::getThisOS())));
  586. }
  587. //==============================================================================
  588. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules, const File& targetFolder, const String& package) const
  589. {
  590. const String className (getActivityName());
  591. if (className.isEmpty())
  592. throw SaveError ("Invalid Android Activity class name: " + androidActivityClass.get());
  593. createDirectoryOrThrow (targetFolder);
  594. LibraryModule* const coreModule = getCoreModule (modules);
  595. if (coreModule != nullptr)
  596. {
  597. File javaDestFile (targetFolder.getChildFile (className + ".java"));
  598. File javaSourceFolder (coreModule->getFolder().getChildFile ("native")
  599. .getChildFile ("java"));
  600. String juceMidiCode, juceMidiImports, juceRuntimePermissionsCode;
  601. juceMidiImports << newLine;
  602. if (androidMinimumSDK.get().getIntValue() >= 23)
  603. {
  604. File javaAndroidMidi (javaSourceFolder.getChildFile ("AndroidMidi.java"));
  605. File javaRuntimePermissions (javaSourceFolder.getChildFile ("AndroidRuntimePermissions.java"));
  606. juceMidiImports << "import android.media.midi.*;" << newLine
  607. << "import android.bluetooth.*;" << newLine
  608. << "import android.bluetooth.le.*;" << newLine;
  609. juceMidiCode = javaAndroidMidi.loadFileAsString().replace ("JuceAppActivity", className);
  610. juceRuntimePermissionsCode = javaRuntimePermissions.loadFileAsString().replace ("JuceAppActivity", className);
  611. }
  612. else
  613. {
  614. juceMidiCode = javaSourceFolder.getChildFile ("AndroidMidiFallback.java")
  615. .loadFileAsString()
  616. .replace ("JuceAppActivity", className);
  617. }
  618. File javaSourceFile (javaSourceFolder.getChildFile ("JuceAppActivity.java"));
  619. StringArray javaSourceLines (StringArray::fromLines (javaSourceFile.loadFileAsString()));
  620. {
  621. MemoryOutputStream newFile;
  622. for (int i = 0; i < javaSourceLines.size(); ++i)
  623. {
  624. const String& line = javaSourceLines[i];
  625. if (line.contains ("$$JuceAndroidMidiImports$$"))
  626. newFile << juceMidiImports;
  627. else if (line.contains ("$$JuceAndroidMidiCode$$"))
  628. newFile << juceMidiCode;
  629. else if (line.contains ("$$JuceAndroidRuntimePermissionsCode$$"))
  630. newFile << juceRuntimePermissionsCode;
  631. else
  632. newFile << line.replace ("JuceAppActivity", className)
  633. .replace ("package com.juce;", "package " + package + ";") << newLine;
  634. }
  635. javaSourceLines = StringArray::fromLines (newFile.toString());
  636. }
  637. while (javaSourceLines.size() > 2
  638. && javaSourceLines[javaSourceLines.size() - 1].trim().isEmpty()
  639. && javaSourceLines[javaSourceLines.size() - 2].trim().isEmpty())
  640. javaSourceLines.remove (javaSourceLines.size() - 1);
  641. overwriteFileIfDifferentOrThrow (javaDestFile, javaSourceLines.joinIntoString (newLine));
  642. }
  643. }
  644. String getActivityName() const
  645. {
  646. return androidActivityClass.get().fromLastOccurrenceOf (".", false, false);
  647. }
  648. String getActivitySubClassName() const
  649. {
  650. String activityPath = androidActivitySubClassName.get();
  651. return (activityPath.isEmpty()) ? getActivityName() : activityPath.fromLastOccurrenceOf (".", false, false);
  652. }
  653. String getActivityClassPackage() const
  654. {
  655. return androidActivityClass.get().upToLastOccurrenceOf (".", false, false);
  656. }
  657. String getJNIActivityClassName() const
  658. {
  659. return androidActivityClass.get().replaceCharacter ('.', '/');
  660. }
  661. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  662. {
  663. for (int i = modules.size(); --i >= 0;)
  664. if (modules.getUnchecked(i)->getID() == "juce_core")
  665. return modules.getUnchecked(i);
  666. return nullptr;
  667. }
  668. //==============================================================================
  669. String getNativeModuleBinaryName (const AndroidBuildConfiguration& config) const
  670. {
  671. return (isLibrary() ? File::createLegalFileName (config.getTargetBinaryNameString().trim()) : "juce_jni");
  672. }
  673. String getAppPlatform() const
  674. {
  675. int ndkVersion = androidMinimumSDK.get().getIntValue();
  676. if (ndkVersion == 9)
  677. ndkVersion = 10; // (doesn't seem to be a version '9')
  678. return "android-" + String (ndkVersion);
  679. }
  680. //==============================================================================
  681. void writeStringsXML (const File& folder) const
  682. {
  683. XmlElement strings ("resources");
  684. XmlElement* resourceName = strings.createNewChildElement ("string");
  685. resourceName->setAttribute ("name", "app_name");
  686. resourceName->addTextElement (projectName);
  687. writeXmlOrThrow (strings, folder.getChildFile ("app/src/main/res/values/string.xml"), "utf-8", 100, true);
  688. }
  689. void writeAndroidManifest (const File& folder) const
  690. {
  691. ScopedPointer<XmlElement> manifest (createManifestXML());
  692. writeXmlOrThrow (*manifest, folder.getChildFile ("src/main/AndroidManifest.xml"), "utf-8", 100, true);
  693. }
  694. void writeIcon (const File& file, const Image& im) const
  695. {
  696. if (im.isValid())
  697. {
  698. createDirectoryOrThrow (file.getParentDirectory());
  699. PNGImageFormat png;
  700. MemoryOutputStream mo;
  701. if (! png.writeImageToStream (im, mo))
  702. throw SaveError ("Can't generate Android icon file");
  703. overwriteFileIfDifferentOrThrow (file, mo);
  704. }
  705. }
  706. void writeIcons (const File& folder) const
  707. {
  708. ScopedPointer<Drawable> bigIcon (getBigIcon());
  709. ScopedPointer<Drawable> smallIcon (getSmallIcon());
  710. if (bigIcon != nullptr && smallIcon != nullptr)
  711. {
  712. const int step = jmax (bigIcon->getWidth(), bigIcon->getHeight()) / 8;
  713. writeIcon (folder.getChildFile ("drawable-xhdpi/icon.png"), getBestIconForSize (step * 8, false));
  714. writeIcon (folder.getChildFile ("drawable-hdpi/icon.png"), getBestIconForSize (step * 6, false));
  715. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), getBestIconForSize (step * 4, false));
  716. writeIcon (folder.getChildFile ("drawable-ldpi/icon.png"), getBestIconForSize (step * 3, false));
  717. }
  718. else if (Drawable* icon = bigIcon != nullptr ? bigIcon : smallIcon)
  719. {
  720. writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), rescaleImageForIcon (*icon, icon->getWidth()));
  721. }
  722. }
  723. void writeAppIcons (const File& folder) const
  724. {
  725. writeIcons (folder.getChildFile ("app/src/main/res/"));
  726. }
  727. static String sanitisePath (String path)
  728. {
  729. return expandHomeFolderToken (path).replace ("\\", "\\\\");
  730. }
  731. static String expandHomeFolderToken (const String& path)
  732. {
  733. String homeFolder = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
  734. return path.replace ("${user.home}", homeFolder)
  735. .replace ("~", homeFolder);
  736. }
  737. //==============================================================================
  738. void addCompileUnits (const Project::Item& projectItem, MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  739. {
  740. if (projectItem.isGroup())
  741. {
  742. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  743. addCompileUnits (projectItem.getChild(i), mo, excludeFromBuild);
  744. }
  745. else if (projectItem.shouldBeAddedToTargetProject())
  746. {
  747. const RelativePath file (projectItem.getFile(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  748. const ProjectType::Target::Type targetType = getProject().getTargetTypeFromFilePath (projectItem.getFile(), true);
  749. mo << " \"" << file.toUnixStyle() << "\"" << newLine;
  750. if ((! projectItem.shouldBeCompiled()) || (! shouldFileBeCompiledByDefault (file))
  751. || (getProject().getProjectType().isAudioPlugin()
  752. && targetType != ProjectType::Target::SharedCodeTarget
  753. && targetType != ProjectType::Target::StandalonePlugIn))
  754. excludeFromBuild.add (file);
  755. }
  756. }
  757. void addCompileUnits (MemoryOutputStream& mo, Array<RelativePath>& excludeFromBuild) const
  758. {
  759. for (int i = 0; i < getAllGroups().size(); ++i)
  760. addCompileUnits (getAllGroups().getReference(i), mo, excludeFromBuild);
  761. }
  762. //==============================================================================
  763. StringArray getCmakeDefinitions() const
  764. {
  765. const String toolchain = gradleToolchain.get();
  766. const bool isClang = (toolchain == "clang");
  767. StringArray cmakeArgs;
  768. cmakeArgs.add ("\"-DANDROID_TOOLCHAIN=" + toolchain + "\"");
  769. cmakeArgs.add ("\"-DANDROID_PLATFORM=" + getAppPlatform() + "\"");
  770. cmakeArgs.add (String ("\"-DANDROID_STL=") + (isClang ? "c++_static" : "gnustl_static") + "\"");
  771. cmakeArgs.add ("\"-DANDROID_CPP_FEATURES=exceptions rtti\"");
  772. cmakeArgs.add ("\"-DANDROID_ARM_MODE=arm\"");
  773. cmakeArgs.add ("\"-DANDROID_ARM_NEON=TRUE\"");
  774. return cmakeArgs;
  775. }
  776. //==============================================================================
  777. StringArray getAndroidCompilerFlags() const
  778. {
  779. StringArray cFlags;
  780. cFlags.add ("\"-fsigned-char\"");
  781. return cFlags;
  782. }
  783. StringArray getAndroidCxxCompilerFlags() const
  784. {
  785. StringArray cxxFlags (getAndroidCompilerFlags());
  786. cxxFlags.add ("\"-std=gnu++11\"");
  787. return cxxFlags;
  788. }
  789. StringArray getProjectCompilerFlags() const
  790. {
  791. StringArray cFlags (getAndroidCompilerFlags());
  792. cFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  793. return cFlags;
  794. }
  795. StringArray getProjectCxxCompilerFlags() const
  796. {
  797. StringArray cxxFlags (getAndroidCxxCompilerFlags());
  798. cxxFlags.addArray (getEscapedFlags (StringArray::fromTokens (getExtraCompilerFlagsString(), true)));
  799. return cxxFlags;
  800. }
  801. //==============================================================================
  802. StringPairArray getAndroidPreprocessorDefs() const
  803. {
  804. StringPairArray defines;
  805. defines.set ("JUCE_ANDROID", "1");
  806. defines.set ("JUCE_ANDROID_API_VERSION", androidMinimumSDK.get());
  807. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  808. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\"" + getJNIActivityClassName() + "\"");
  809. return defines;
  810. }
  811. StringPairArray getProjectPreprocessorDefs() const
  812. {
  813. StringPairArray defines (getAndroidPreprocessorDefs());
  814. return mergePreprocessorDefs (defines, getProject().getPreprocessorDefs());
  815. }
  816. StringPairArray getConfigPreprocessorDefs (const BuildConfiguration& config) const
  817. {
  818. StringPairArray cfgDefines (config.getUniquePreprocessorDefs());
  819. if (config.isDebug())
  820. {
  821. cfgDefines.set ("DEBUG", "1");
  822. cfgDefines.set ("_DEBUG", "1");
  823. }
  824. else
  825. {
  826. cfgDefines.set ("NDEBUG", "1");
  827. }
  828. return cfgDefines;
  829. }
  830. //==============================================================================
  831. StringArray getAndroidLibraries() const
  832. {
  833. StringArray libraries;
  834. libraries.add ("log");
  835. libraries.add ("android");
  836. libraries.add (androidMinimumSDK.get().getIntValue() >= 18 ? "GLESv3" : "GLESv2");
  837. libraries.add ("EGL");
  838. return libraries;
  839. }
  840. StringArray getProjectLibraries() const
  841. {
  842. StringArray libraries (getAndroidLibraries());
  843. libraries.addArray (StringArray::fromLines (getExternalLibrariesString()));
  844. return libraries;
  845. }
  846. //==============================================================================
  847. StringArray getHeaderSearchPaths (const BuildConfiguration& config) const
  848. {
  849. StringArray paths (extraSearchPaths);
  850. paths.addArray (config.getHeaderSearchPaths());
  851. paths = getCleanedStringArray (paths);
  852. return paths;
  853. }
  854. //==============================================================================
  855. String escapeDirectoryForCmake (const String& path) const
  856. {
  857. RelativePath relative =
  858. RelativePath (path, RelativePath::buildTargetFolder)
  859. .rebased (getTargetFolder(), getTargetFolder().getChildFile ("app"), RelativePath::buildTargetFolder);
  860. return relative.toUnixStyle();
  861. }
  862. void writeCmakePathLines (MemoryOutputStream& mo, const String& prefix, const String& firstLine, const StringArray& paths) const
  863. {
  864. if (paths.size() > 0)
  865. {
  866. mo << prefix << firstLine << newLine;
  867. for (auto& path : paths)
  868. mo << prefix << " \"" << escapeDirectoryForCmake (path) << "\"" << newLine;
  869. mo << prefix << ")" << newLine << newLine;
  870. }
  871. }
  872. static StringArray getEscapedPreprocessorDefs (const StringPairArray& defs)
  873. {
  874. StringArray escapedDefs;
  875. for (int i = 0; i < defs.size(); ++i)
  876. {
  877. String escaped ("\"-D" + defs.getAllKeys()[i]);
  878. String value = defs.getAllValues()[i];
  879. if (value.isNotEmpty())
  880. {
  881. value = value.replace ("\"", "\\\"");
  882. if (value.containsChar (L' '))
  883. value = "\\\"" + value + "\\\"";
  884. escaped += ("=" + value + "\"");
  885. }
  886. escapedDefs.add (escaped);
  887. }
  888. return escapedDefs;
  889. }
  890. static StringArray getEscapedFlags (const StringArray& flags)
  891. {
  892. StringArray escaped;
  893. for (auto& flag : flags)
  894. escaped.add ("\"" + flag + "\"");
  895. return escaped;
  896. }
  897. //==============================================================================
  898. XmlElement* createManifestXML() const
  899. {
  900. XmlElement* manifest = new XmlElement ("manifest");
  901. manifest->setAttribute ("xmlns:android", "http://schemas.android.com/apk/res/android");
  902. manifest->setAttribute ("android:versionCode", androidVersionCode.get());
  903. manifest->setAttribute ("android:versionName", project.getVersionString());
  904. manifest->setAttribute ("package", getActivityClassPackage());
  905. if (! isLibrary())
  906. {
  907. XmlElement* screens = manifest->createNewChildElement ("supports-screens");
  908. screens->setAttribute ("android:smallScreens", "true");
  909. screens->setAttribute ("android:normalScreens", "true");
  910. screens->setAttribute ("android:largeScreens", "true");
  911. screens->setAttribute ("android:anyDensity", "true");
  912. }
  913. XmlElement* sdk = manifest->createNewChildElement ("uses-sdk");
  914. sdk->setAttribute ("android:minSdkVersion", androidMinimumSDK.get());
  915. sdk->setAttribute ("android:targetSdkVersion", androidMinimumSDK.get());
  916. {
  917. const StringArray permissions (getPermissionsRequired());
  918. for (int i = permissions.size(); --i >= 0;)
  919. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  920. }
  921. if (project.getModules().isModuleEnabled ("juce_opengl"))
  922. {
  923. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  924. feature->setAttribute ("android:glEsVersion", (androidMinimumSDK.get().getIntValue() >= 18 ? "0x00030000" : "0x00020000"));
  925. feature->setAttribute ("android:required", "true");
  926. }
  927. if (! isLibrary())
  928. {
  929. XmlElement* app = manifest->createNewChildElement ("application");
  930. app->setAttribute ("android:label", "@string/app_name");
  931. if (androidTheme.get().isNotEmpty())
  932. app->setAttribute ("android:theme", androidTheme.get());
  933. {
  934. ScopedPointer<Drawable> bigIcon (getBigIcon()), smallIcon (getSmallIcon());
  935. if (bigIcon != nullptr || smallIcon != nullptr)
  936. app->setAttribute ("android:icon", "@drawable/icon");
  937. }
  938. if (androidMinimumSDK.get().getIntValue() >= 11)
  939. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  940. XmlElement* act = app->createNewChildElement ("activity");
  941. act->setAttribute ("android:name", getActivitySubClassName());
  942. act->setAttribute ("android:label", "@string/app_name");
  943. String configChanges ("keyboardHidden|orientation");
  944. if (androidMinimumSDK.get().getIntValue() >= 13)
  945. configChanges += "|screenSize";
  946. act->setAttribute ("android:configChanges", configChanges);
  947. act->setAttribute ("android:screenOrientation", androidScreenOrientation.get());
  948. XmlElement* intent = act->createNewChildElement ("intent-filter");
  949. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  950. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  951. }
  952. return manifest;
  953. }
  954. StringArray getPermissionsRequired() const
  955. {
  956. StringArray s;
  957. s.addTokens (androidOtherPermissions.get(), ", ", "");
  958. if (androidInternetNeeded.get())
  959. s.add ("android.permission.INTERNET");
  960. if (androidMicNeeded.get())
  961. s.add ("android.permission.RECORD_AUDIO");
  962. if (androidBluetoothNeeded.get())
  963. {
  964. s.add ("android.permission.BLUETOOTH");
  965. s.add ("android.permission.BLUETOOTH_ADMIN");
  966. s.add ("android.permission.ACCESS_COARSE_LOCATION");
  967. }
  968. return getCleanedStringArray (s);
  969. }
  970. //==============================================================================
  971. bool isLibrary() const
  972. {
  973. return getProject().getProjectType().isDynamicLibrary()
  974. || getProject().getProjectType().isStaticLibrary();
  975. }
  976. static String toGradleList (const StringArray& array)
  977. {
  978. StringArray escapedArray;
  979. for (auto element : array)
  980. escapedArray.add ("\"" + element.replace ("\\", "\\\\").replace ("\"", "\\\"") + "\"");
  981. return escapedArray.joinIntoString (", ");
  982. }
  983. //==============================================================================
  984. Value sdkPath, ndkPath;
  985. const File AndroidExecutable;
  986. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter)
  987. };
  988. ProjectExporter* createAndroidExporter (Project& p, const ValueTree& t)
  989. {
  990. return new AndroidProjectExporter (p, t);
  991. }
  992. ProjectExporter* createAndroidExporterForSetting (Project& p, const ValueTree& t)
  993. {
  994. return AndroidProjectExporter::createForSettings (p, t);
  995. }