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.

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