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.

651 lines
29KB

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