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.

638 lines
28KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. static const char* getNameAndroid() { return "Android Project"; }
  22. static const char* getValueTreeTypeName() { return "ANDROID"; }
  23. static AndroidProjectExporter* createForSettings (Project& project, const ValueTree& settings)
  24. {
  25. if (settings.hasType (getValueTreeTypeName()))
  26. return new AndroidProjectExporter (project, settings);
  27. return nullptr;
  28. }
  29. //==============================================================================
  30. AndroidProjectExporter (Project& p, const ValueTree& t) : ProjectExporter (p, t)
  31. {
  32. name = getNameAndroid();
  33. if (getTargetLocationString().isEmpty())
  34. getTargetLocationValue() = getDefaultBuildsRootFolder() + "Android";
  35. if (getActivityClassPath().isEmpty())
  36. getActivityClassPathValue() = createDefaultClassName();
  37. if (getSDKPathString().isEmpty()) getSDKPathValue() = "${user.home}/SDKs/android-sdk";
  38. if (getNDKPathString().isEmpty()) getNDKPathValue() = "${user.home}/SDKs/android-ndk";
  39. if (getMinimumSDKVersionString().isEmpty())
  40. getMinimumSDKVersionValue() = 8;
  41. if (getInternetNeededValue().toString().isEmpty())
  42. getInternetNeededValue() = true;
  43. if (getKeyStoreValue().getValue().isVoid()) getKeyStoreValue() = "${user.home}/.android/debug.keystore";
  44. if (getKeyStorePassValue().getValue().isVoid()) getKeyStorePassValue() = "android";
  45. if (getKeyAliasValue().getValue().isVoid()) getKeyAliasValue() = "androiddebugkey";
  46. if (getKeyAliasPassValue().getValue().isVoid()) getKeyAliasPassValue() = "android";
  47. }
  48. //==============================================================================
  49. bool launchProject() { return false; }
  50. bool isAndroid() const { return true; }
  51. bool usesMMFiles() const { return false; }
  52. bool canCopeWithDuplicateFiles() { return false; }
  53. void createExporterProperties (PropertyListBuilder& props)
  54. {
  55. props.add (new TextPropertyComponent (getActivityClassPathValue(), "Android Activity class name", 256, false),
  56. "The full java class name to use for the app's Activity class.");
  57. props.add (new TextPropertyComponent (getSDKPathValue(), "Android SDK Path", 1024, false),
  58. "The path to the Android SDK folder on the target build machine");
  59. props.add (new TextPropertyComponent (getNDKPathValue(), "Android NDK Path", 1024, false),
  60. "The path to the Android NDK folder on the target build machine");
  61. props.add (new TextPropertyComponent (getMinimumSDKVersionValue(), "Minimum SDK version", 32, false),
  62. "The number of the minimum version of the Android SDK that the app requires");
  63. props.add (new BooleanPropertyComponent (getCPP11EnabledValue(), "Enable C++11 features", "Enable the -std=c++0x flag"),
  64. "If enabled, this will set the -std=c++0x flag for the build.");
  65. props.add (new BooleanPropertyComponent (getInternetNeededValue(), "Internet Access", "Specify internet access permission in the manifest"),
  66. "If enabled, this will set the android.permission.INTERNET flag in the manifest.");
  67. props.add (new BooleanPropertyComponent (getAudioRecordNeededValue(), "Audio Input Required", "Specify audio record permission in the manifest"),
  68. "If enabled, this will set the android.permission.RECORD_AUDIO flag in the manifest.");
  69. props.add (new TextPropertyComponent (getOtherPermissionsValue(), "Custom permissions", 2048, false),
  70. "A space-separated list of other permission flags that should be added to the manifest.");
  71. props.add (new TextPropertyComponent (getKeyStoreValue(), "Key Signing: key.store", 2048, false),
  72. "The key.store value, used when signing the package.");
  73. props.add (new TextPropertyComponent (getKeyStorePassValue(), "Key Signing: key.store.password", 2048, false),
  74. "The key.store password, used when signing the package.");
  75. props.add (new TextPropertyComponent (getKeyAliasValue(), "Key Signing: key.alias", 2048, false),
  76. "The key.alias value, used when signing the package.");
  77. props.add (new TextPropertyComponent (getKeyAliasPassValue(), "Key Signing: key.alias.password", 2048, false),
  78. "The key.alias password, used when signing the package.");
  79. }
  80. Value getActivityClassPathValue() { return getSetting (Ids::androidActivityClass); }
  81. String getActivityClassPath() const { return settings [Ids::androidActivityClass]; }
  82. Value getSDKPathValue() { return getSetting (Ids::androidSDKPath); }
  83. String getSDKPathString() const { return settings [Ids::androidSDKPath]; }
  84. Value getNDKPathValue() { return getSetting (Ids::androidNDKPath); }
  85. String getNDKPathString() const { return settings [Ids::androidNDKPath]; }
  86. Value getKeyStoreValue() { return getSetting (Ids::androidKeyStore); }
  87. String getKeyStoreString() const { return settings [Ids::androidKeyStore]; }
  88. Value getKeyStorePassValue() { return getSetting (Ids::androidKeyStorePass); }
  89. String getKeyStorePassString() const { return settings [Ids::androidKeyStorePass]; }
  90. Value getKeyAliasValue() { return getSetting (Ids::androidKeyAlias); }
  91. String getKeyAliasString() const { return settings [Ids::androidKeyAlias]; }
  92. Value getKeyAliasPassValue() { return getSetting (Ids::androidKeyAliasPass); }
  93. String getKeyAliasPassString() const { return settings [Ids::androidKeyAliasPass]; }
  94. Value getInternetNeededValue() { return getSetting (Ids::androidInternetNeeded); }
  95. bool getInternetNeeded() const { return settings [Ids::androidInternetNeeded]; }
  96. Value getAudioRecordNeededValue() { return getSetting (Ids::androidMicNeeded); }
  97. bool getAudioRecordNeeded() const { return settings [Ids::androidMicNeeded]; }
  98. Value getMinimumSDKVersionValue() { return getSetting (Ids::androidMinimumSDK); }
  99. String getMinimumSDKVersionString() const { return settings [Ids::androidMinimumSDK]; }
  100. Value getOtherPermissionsValue() { return getSetting (Ids::androidOtherPermissions); }
  101. String getOtherPermissions() const { return settings [Ids::androidOtherPermissions]; }
  102. Value getCPP11EnabledValue() { return getSetting (Ids::androidCpp11); }
  103. bool isCPP11Enabled() const { return settings [Ids::androidCpp11]; }
  104. String createDefaultClassName() const
  105. {
  106. String s (project.getBundleIdentifier().toString().toLowerCase());
  107. if (s.length() > 5
  108. && s.containsChar ('.')
  109. && s.containsOnly ("abcdefghijklmnopqrstuvwxyz_.")
  110. && ! s.startsWithChar ('.'))
  111. {
  112. if (! s.endsWithChar ('.'))
  113. s << ".";
  114. }
  115. else
  116. {
  117. s = "com.yourcompany.";
  118. }
  119. return s + CodeHelpers::makeValidIdentifier (project.getProjectFilenameRoot(), false, true, false);
  120. }
  121. //==============================================================================
  122. void create (const OwnedArray<LibraryModule>& modules) const
  123. {
  124. const File target (getTargetFolder());
  125. const File jniFolder (target.getChildFile ("jni"));
  126. copyActivityJavaFiles (modules);
  127. createDirectoryOrThrow (jniFolder);
  128. createDirectoryOrThrow (target.getChildFile ("res").getChildFile ("values"));
  129. createDirectoryOrThrow (target.getChildFile ("libs"));
  130. createDirectoryOrThrow (target.getChildFile ("bin"));
  131. {
  132. ScopedPointer<XmlElement> manifest (createManifestXML());
  133. writeXmlOrThrow (*manifest, target.getChildFile ("AndroidManifest.xml"), "utf-8", 100, true);
  134. }
  135. writeApplicationMk (jniFolder.getChildFile ("Application.mk"));
  136. writeAndroidMk (jniFolder.getChildFile ("Android.mk"));
  137. {
  138. ScopedPointer<XmlElement> antBuildXml (createAntBuildXML());
  139. writeXmlOrThrow (*antBuildXml, target.getChildFile ("build.xml"), "UTF-8", 100);
  140. }
  141. writeProjectPropertiesFile (target.getChildFile ("project.properties"));
  142. writeLocalPropertiesFile (target.getChildFile ("local.properties"));
  143. writeStringsFile (target.getChildFile ("res/values/strings.xml"));
  144. const Image bigIcon (getBigIcon());
  145. const Image smallIcon (getSmallIcon());
  146. if (bigIcon.isValid() && smallIcon.isValid())
  147. {
  148. const int step = jmax (bigIcon.getWidth(), bigIcon.getHeight()) / 8;
  149. writeIcon (target.getChildFile ("res/drawable-xhdpi/icon.png"), getBestIconForSize (step * 8, false));
  150. writeIcon (target.getChildFile ("res/drawable-hdpi/icon.png"), getBestIconForSize (step * 6, false));
  151. writeIcon (target.getChildFile ("res/drawable-mdpi/icon.png"), getBestIconForSize (step * 4, false));
  152. writeIcon (target.getChildFile ("res/drawable-ldpi/icon.png"), getBestIconForSize (step * 3, false));
  153. }
  154. else
  155. {
  156. writeIcon (target.getChildFile ("res/drawable-mdpi/icon.png"), bigIcon.isValid() ? bigIcon : smallIcon);
  157. }
  158. }
  159. protected:
  160. //==============================================================================
  161. class AndroidBuildConfiguration : public BuildConfiguration
  162. {
  163. public:
  164. AndroidBuildConfiguration (Project& p, const ValueTree& settings)
  165. : BuildConfiguration (p, settings)
  166. {
  167. if (getArchitectures().isEmpty())
  168. getArchitecturesValue() = "armeabi armeabi-v7a";
  169. }
  170. Value getArchitecturesValue() { return getValue (Ids::androidArchitectures); }
  171. String getArchitectures() const { return config [Ids::androidArchitectures]; }
  172. void createConfigProperties (PropertyListBuilder& props)
  173. {
  174. props.add (new TextPropertyComponent (getArchitecturesValue(), "Architectures", 256, false),
  175. "A list of the ARM architectures to build (for a fat binary).");
  176. }
  177. };
  178. BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const
  179. {
  180. return new AndroidBuildConfiguration (project, v);
  181. }
  182. private:
  183. //==============================================================================
  184. XmlElement* createManifestXML() const
  185. {
  186. XmlElement* manifest = new XmlElement ("manifest");
  187. manifest->setAttribute ("xmlns:android", "http://schemas.android.com/apk/res/android");
  188. manifest->setAttribute ("android:versionCode", "1");
  189. manifest->setAttribute ("android:versionName", "1.0");
  190. manifest->setAttribute ("package", getActivityClassPackage());
  191. XmlElement* screens = manifest->createNewChildElement ("supports-screens");
  192. screens->setAttribute ("android:smallScreens", "true");
  193. screens->setAttribute ("android:normalScreens", "true");
  194. screens->setAttribute ("android:largeScreens", "true");
  195. //screens->setAttribute ("android:xlargeScreens", "true");
  196. screens->setAttribute ("android:anyDensity", "true");
  197. XmlElement* sdk = manifest->createNewChildElement ("uses-sdk");
  198. sdk->setAttribute ("android:minSdkVersion", getMinimumSDKVersionString());
  199. sdk->setAttribute ("android:targetSdkVersion", "11");
  200. {
  201. const StringArray permissions (getPermissionsRequired());
  202. for (int i = permissions.size(); --i >= 0;)
  203. manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]);
  204. }
  205. if (project.isModuleEnabled ("juce_opengl"))
  206. {
  207. XmlElement* feature = manifest->createNewChildElement ("uses-feature");
  208. feature->setAttribute ("android:glEsVersion", "0x00020000");
  209. feature->setAttribute ("android:required", "true");
  210. }
  211. XmlElement* app = manifest->createNewChildElement ("application");
  212. app->setAttribute ("android:label", "@string/app_name");
  213. app->setAttribute ("android:icon", "@drawable/icon");
  214. if (getMinimumSDKVersionString().getIntValue() >= 11)
  215. app->setAttribute ("android:hardwareAccelerated", "false"); // (using the 2D acceleration slows down openGL)
  216. XmlElement* act = app->createNewChildElement ("activity");
  217. act->setAttribute ("android:name", getActivityName());
  218. act->setAttribute ("android:label", "@string/app_name");
  219. act->setAttribute ("android:configChanges", "keyboardHidden|orientation");
  220. XmlElement* intent = act->createNewChildElement ("intent-filter");
  221. intent->createNewChildElement ("action")->setAttribute ("android:name", "android.intent.action.MAIN");
  222. intent->createNewChildElement ("category")->setAttribute ("android:name", "android.intent.category.LAUNCHER");
  223. return manifest;
  224. }
  225. StringArray getPermissionsRequired() const
  226. {
  227. StringArray s;
  228. s.addTokens (getOtherPermissions(), ", ", "");
  229. if (getInternetNeeded()) s.add ("android.permission.INTERNET");
  230. if (getAudioRecordNeeded()) s.add ("android.permission.RECORD_AUDIO");
  231. s.trim();
  232. s.removeDuplicates (false);
  233. return s;
  234. }
  235. //==============================================================================
  236. void findAllFilesToCompile (const Project::Item& projectItem, Array<RelativePath>& results) const
  237. {
  238. if (projectItem.isGroup())
  239. {
  240. for (int i = 0; i < projectItem.getNumChildren(); ++i)
  241. findAllFilesToCompile (projectItem.getChild(i), results);
  242. }
  243. else
  244. {
  245. if (projectItem.shouldBeCompiled())
  246. results.add (RelativePath (projectItem.getFile(), getTargetFolder(), RelativePath::buildTargetFolder));
  247. }
  248. }
  249. //==============================================================================
  250. String getActivityName() const
  251. {
  252. return getActivityClassPath().fromLastOccurrenceOf (".", false, false);
  253. }
  254. String getActivityClassPackage() const
  255. {
  256. return getActivityClassPath().upToLastOccurrenceOf (".", false, false);
  257. }
  258. String getJNIActivityClassName() const
  259. {
  260. return getActivityClassPath().replaceCharacter ('.', '/');
  261. }
  262. static LibraryModule* getCoreModule (const OwnedArray<LibraryModule>& modules)
  263. {
  264. for (int i = modules.size(); --i >= 0;)
  265. if (modules.getUnchecked(i)->getID() == "juce_core")
  266. return modules.getUnchecked(i);
  267. return nullptr;
  268. }
  269. void copyActivityJavaFiles (const OwnedArray<LibraryModule>& modules) const
  270. {
  271. const String className (getActivityName());
  272. const String package (getActivityClassPackage());
  273. String path (package.replaceCharacter ('.', File::separator));
  274. if (path.isEmpty() || className.isEmpty())
  275. throw SaveError ("Invalid Android Activity class name: " + getActivityClassPath());
  276. const File classFolder (getTargetFolder().getChildFile ("src")
  277. .getChildFile (path));
  278. createDirectoryOrThrow (classFolder);
  279. LibraryModule* const coreModule = getCoreModule (modules);
  280. if (coreModule == nullptr)
  281. throw SaveError ("To build an Android app, the juce_core module must be included in your project!");
  282. File javaDestFile (classFolder.getChildFile (className + ".java"));
  283. File javaSourceFile (coreModule->getFolder().getChildFile ("native")
  284. .getChildFile ("java")
  285. .getChildFile ("JuceAppActivity.java"));
  286. MemoryOutputStream newFile;
  287. newFile << javaSourceFile.loadFileAsString()
  288. .replace ("JuceAppActivity", className)
  289. .replace ("package com.juce;", "package " + package + ";");
  290. overwriteFileIfDifferentOrThrow (javaDestFile, newFile);
  291. }
  292. void writeApplicationMk (const File& file) const
  293. {
  294. MemoryOutputStream mo;
  295. mo << "# Automatically generated makefile, created by the Introjucer" << newLine
  296. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  297. << newLine
  298. << "APP_STL := gnustl_static" << newLine
  299. << "APP_CPPFLAGS += -fsigned-char -fexceptions -frtti -Wno-psabi" << newLine
  300. << "APP_PLATFORM := " << getAppPlatform() << newLine;
  301. overwriteFileIfDifferentOrThrow (file, mo);
  302. }
  303. void writeAndroidMk (const File& file) const
  304. {
  305. Array<RelativePath> files;
  306. for (int i = 0; i < getAllGroups().size(); ++i)
  307. findAllFilesToCompile (getAllGroups().getReference(i), files);
  308. MemoryOutputStream mo;
  309. writeAndroidMk (mo, files);
  310. overwriteFileIfDifferentOrThrow (file, mo);
  311. }
  312. void writeAndroidMk (OutputStream& out, const Array<RelativePath>& files) const
  313. {
  314. out << "# Automatically generated makefile, created by the Introjucer" << newLine
  315. << "# Don't edit this file! Your changes will be overwritten when you re-save the Introjucer project!" << newLine
  316. << newLine
  317. << "LOCAL_PATH := $(call my-dir)" << newLine
  318. << newLine
  319. << "include $(CLEAR_VARS)" << newLine
  320. << newLine
  321. << "LOCAL_MODULE := juce_jni" << newLine
  322. << "LOCAL_SRC_FILES := \\" << newLine;
  323. for (int i = 0; i < files.size(); ++i)
  324. out << " ../" << escapeSpaces (files.getReference(i).toUnixStyle()) << "\\" << newLine;
  325. String debugSettings, releaseSettings;
  326. out << newLine
  327. << "ifeq ($(CONFIG),Debug)" << newLine;
  328. writeConfigSettings (out, true);
  329. out << "else" << newLine;
  330. writeConfigSettings (out, false);
  331. out << "endif" << newLine
  332. << newLine
  333. << "include $(BUILD_SHARED_LIBRARY)" << newLine;
  334. }
  335. void writeConfigSettings (OutputStream& out, bool forDebug) const
  336. {
  337. for (ConstConfigIterator config (*this); config.next();)
  338. {
  339. if (config->isDebug() == forDebug)
  340. {
  341. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  342. String cppFlags;
  343. cppFlags << createCPPFlags (androidConfig)
  344. << (" " + replacePreprocessorTokens (androidConfig, getExtraCompilerFlagsString()).trim()).trimEnd()
  345. << newLine
  346. << getLDLIBS (androidConfig).trimEnd()
  347. << newLine;
  348. out << " LOCAL_CPPFLAGS += " << cppFlags;
  349. out << " LOCAL_CFLAGS += " << cppFlags;
  350. break;
  351. }
  352. }
  353. }
  354. String getLDLIBS (const AndroidBuildConfiguration& config) const
  355. {
  356. return " LOCAL_LDLIBS :=" + config.getGCCLibraryPathFlags()
  357. + " -llog -lGLESv2 " + getExternalLibraryFlags (config)
  358. + " " + replacePreprocessorTokens (config, getExtraLinkerFlagsString());
  359. }
  360. String createIncludePathFlags (const BuildConfiguration& config) const
  361. {
  362. String flags;
  363. StringArray searchPaths (extraSearchPaths);
  364. searchPaths.addArray (config.getHeaderSearchPaths());
  365. searchPaths.removeDuplicates (false);
  366. for (int i = 0; i < searchPaths.size(); ++i)
  367. flags << " -I " << FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i])).quoted();
  368. return flags;
  369. }
  370. String createCPPFlags (const BuildConfiguration& config) const
  371. {
  372. StringPairArray defines;
  373. defines.set ("JUCE_ANDROID", "1");
  374. defines.set ("JUCE_ANDROID_API_VERSION", getMinimumSDKVersionString());
  375. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  376. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\\\"" + getJNIActivityClassName() + "\\\"");
  377. String flags ("-fsigned-char -fexceptions -frtti");
  378. if (config.isDebug())
  379. {
  380. flags << " -g";
  381. defines.set ("DEBUG", "1");
  382. defines.set ("_DEBUG", "1");
  383. }
  384. else
  385. {
  386. defines.set ("NDEBUG", "1");
  387. }
  388. flags << createIncludePathFlags (config)
  389. << " -O" << config.getGCCOptimisationFlag();
  390. if (isCPP11Enabled())
  391. flags << " -std=c++0x";
  392. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  393. return flags + createGCCPreprocessorFlags (defines);
  394. }
  395. //==============================================================================
  396. XmlElement* createAntBuildXML() const
  397. {
  398. XmlElement* proj = new XmlElement ("project");
  399. proj->setAttribute ("name", projectName);
  400. proj->setAttribute ("default", "debug");
  401. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "local.properties");
  402. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "project.properties");
  403. {
  404. XmlElement* target = proj->createNewChildElement ("target");
  405. target->setAttribute ("name", "clean");
  406. XmlElement* executable = target->createNewChildElement ("exec");
  407. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  408. executable->setAttribute ("dir", "${basedir}");
  409. executable->setAttribute ("failonerror", "true");
  410. executable->createNewChildElement ("arg")->setAttribute ("value", "clean");
  411. }
  412. {
  413. XmlElement* target = proj->createNewChildElement ("target");
  414. target->setAttribute ("name", "-pre-build");
  415. addDebugConditionClause (target, "makefileConfig", "Debug", "Release");
  416. addDebugConditionClause (target, "ndkDebugValue", "NDK_DEBUG=1", "NDK_DEBUG=0");
  417. String debugABIs, releaseABIs;
  418. for (ConstConfigIterator config (*this); config.next();)
  419. {
  420. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  421. if (config->isDebug())
  422. debugABIs = androidConfig.getArchitectures();
  423. else
  424. releaseABIs = androidConfig.getArchitectures();
  425. }
  426. addDebugConditionClause (target, "app_abis", debugABIs, releaseABIs);
  427. XmlElement* executable = target->createNewChildElement ("exec");
  428. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  429. executable->setAttribute ("dir", "${basedir}");
  430. executable->setAttribute ("failonerror", "true");
  431. executable->createNewChildElement ("arg")->setAttribute ("value", "--jobs=2");
  432. executable->createNewChildElement ("arg")->setAttribute ("value", "CONFIG=${makefileConfig}");
  433. executable->createNewChildElement ("arg")->setAttribute ("value", "${ndkDebugValue}");
  434. executable->createNewChildElement ("arg")->setAttribute ("value", "APP_ABI=${app_abis}");
  435. target->createNewChildElement ("delete")->setAttribute ("file", "${out.final.file}");
  436. target->createNewChildElement ("delete")->setAttribute ("file", "${out.packaged.file}");
  437. }
  438. proj->createNewChildElement ("import")->setAttribute ("file", "${sdk.dir}/tools/ant/build.xml");
  439. return proj;
  440. }
  441. void addDebugConditionClause (XmlElement* target, const String& property,
  442. const String& debugValue, const String& releaseValue) const
  443. {
  444. XmlElement* condition = target->createNewChildElement ("condition");
  445. condition->setAttribute ("property", property);
  446. condition->setAttribute ("value", debugValue);
  447. condition->setAttribute ("else", releaseValue);
  448. XmlElement* equals = condition->createNewChildElement ("equals");
  449. equals->setAttribute ("arg1", "${ant.project.invoked-targets}");
  450. equals->setAttribute ("arg2", "debug");
  451. }
  452. String getAppPlatform() const
  453. {
  454. int ndkVersion = getMinimumSDKVersionString().getIntValue();
  455. if (ndkVersion == 9)
  456. ndkVersion = 10; // (doesn't seem to be a version '9')
  457. return "android-" + String (ndkVersion);
  458. }
  459. void writeProjectPropertiesFile (const File& file) const
  460. {
  461. MemoryOutputStream mo;
  462. mo << "# This file is used to override default values used by the Ant build system." << newLine
  463. << "# It is automatically generated - DO NOT EDIT IT or your changes will be lost!." << newLine
  464. << newLine
  465. << "target=" << getAppPlatform() << newLine
  466. << newLine;
  467. overwriteFileIfDifferentOrThrow (file, mo);
  468. }
  469. void writeLocalPropertiesFile (const File& file) const
  470. {
  471. MemoryOutputStream mo;
  472. mo << "# This file is used to override default values used by the Ant build system." << newLine
  473. << "# It is automatically generated by the Introjucer - DO NOT EDIT IT or your changes will be lost!." << newLine
  474. << newLine
  475. << "sdk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getSDKPathString())) << newLine
  476. << "ndk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getNDKPathString())) << newLine
  477. << "key.store=" << getKeyStoreString() << newLine
  478. << "key.alias=" << getKeyAliasString() << newLine
  479. << "key.store.password=" << getKeyStorePassString() << newLine
  480. << "key.alias.password=" << getKeyAliasPassString() << newLine
  481. << newLine;
  482. overwriteFileIfDifferentOrThrow (file, mo);
  483. }
  484. void writeIcon (const File& file, const Image& im) const
  485. {
  486. if (im.isValid())
  487. {
  488. createDirectoryOrThrow (file.getParentDirectory());
  489. PNGImageFormat png;
  490. MemoryOutputStream mo;
  491. if (! png.writeImageToStream (im, mo))
  492. throw SaveError ("Can't generate Android icon file");
  493. overwriteFileIfDifferentOrThrow (file, mo);
  494. }
  495. }
  496. void writeStringsFile (const File& file) const
  497. {
  498. XmlElement strings ("resources");
  499. XmlElement* resourceName = strings.createNewChildElement ("string");
  500. resourceName->setAttribute ("name", "app_name");
  501. resourceName->addTextElement (projectName);
  502. writeXmlOrThrow (strings, file, "utf-8", 100);
  503. }
  504. //==============================================================================
  505. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter)
  506. };