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.

667 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 (*config) << newLine
  352. << getDynamicLibs (androidConfig);
  353. break;
  354. }
  355. }
  356. }
  357. String getDynamicLibs (const AndroidBuildConfiguration& config) const
  358. {
  359. String flags (" LOCAL_LDLIBS :=");
  360. flags << config.getGCCLibraryPathFlags();
  361. {
  362. StringArray libs;
  363. libs.add ("log");
  364. libs.add ("GLESv2");
  365. for (int i = 0; i < libs.size(); ++i)
  366. flags << " -l" << libs[i];
  367. }
  368. return flags + newLine;
  369. }
  370. String createIncludePathFlags (const BuildConfiguration& config) const
  371. {
  372. String flags;
  373. StringArray searchPaths (extraSearchPaths);
  374. searchPaths.addArray (config.getHeaderSearchPaths());
  375. searchPaths.removeDuplicates (false);
  376. for (int i = 0; i < searchPaths.size(); ++i)
  377. flags << " -I " << FileHelpers::unixStylePath (replacePreprocessorTokens (config, searchPaths[i])).quoted();
  378. return flags;
  379. }
  380. String createCPPFlags (const BuildConfiguration& config) const
  381. {
  382. StringPairArray defines;
  383. defines.set ("JUCE_ANDROID", "1");
  384. defines.set ("JUCE_ANDROID_API_VERSION", getMinimumSDKVersionString());
  385. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSNAME", getJNIActivityClassName().replaceCharacter ('/', '_'));
  386. defines.set ("JUCE_ANDROID_ACTIVITY_CLASSPATH", "\\\"" + getJNIActivityClassName() + "\\\"");
  387. String flags ("-fsigned-char -fexceptions -frtti");
  388. if (config.isDebug())
  389. {
  390. flags << " -g";
  391. defines.set ("DEBUG", "1");
  392. defines.set ("_DEBUG", "1");
  393. }
  394. else
  395. {
  396. defines.set ("NDEBUG", "1");
  397. }
  398. flags << createIncludePathFlags (config)
  399. << " -O" << config.getGCCOptimisationFlag();
  400. defines = mergePreprocessorDefs (defines, getAllPreprocessorDefs (config));
  401. return flags + createGCCPreprocessorFlags (defines);
  402. }
  403. //==============================================================================
  404. XmlElement* createAntBuildXML() const
  405. {
  406. XmlElement* proj = new XmlElement ("project");
  407. proj->setAttribute ("name", projectName);
  408. proj->setAttribute ("default", "debug");
  409. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "local.properties");
  410. proj->createNewChildElement ("loadproperties")->setAttribute ("srcFile", "project.properties");
  411. XmlElement* path = proj->createNewChildElement ("path");
  412. path->setAttribute ("id", "android.antlibs");
  413. path->createNewChildElement ("pathelement")->setAttribute ("path", "${sdk.dir}/tools/lib/anttasks.jar");
  414. path->createNewChildElement ("pathelement")->setAttribute ("path", "${sdk.dir}/tools/lib/sdklib.jar");
  415. path->createNewChildElement ("pathelement")->setAttribute ("path", "${sdk.dir}/tools/lib/androidprefs.jar");
  416. XmlElement* taskdef = proj->createNewChildElement ("taskdef");
  417. taskdef->setAttribute ("name", "setup");
  418. taskdef->setAttribute ("classname", "com.android.ant.SetupTask");
  419. taskdef->setAttribute ("classpathref", "android.antlibs");
  420. {
  421. XmlElement* target = proj->createNewChildElement ("target");
  422. target->setAttribute ("name", "clean");
  423. XmlElement* executable = target->createNewChildElement ("exec");
  424. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  425. executable->setAttribute ("dir", "${basedir}");
  426. executable->setAttribute ("failonerror", "true");
  427. executable->createNewChildElement ("arg")->setAttribute ("value", "clean");
  428. }
  429. {
  430. XmlElement* target = proj->createNewChildElement ("target");
  431. target->setAttribute ("name", "-pre-build");
  432. addDebugConditionClause (target, "makefileConfig", "Debug", "Release");
  433. addDebugConditionClause (target, "ndkDebugValue", "NDK_DEBUG=1", "NDK_DEBUG=0");
  434. String debugABIs, releaseABIs;
  435. for (ConstConfigIterator config (*this); config.next();)
  436. {
  437. const AndroidBuildConfiguration& androidConfig = dynamic_cast <const AndroidBuildConfiguration&> (*config);
  438. if (config->isDebug())
  439. debugABIs = androidConfig.getArchitectures();
  440. else
  441. releaseABIs = androidConfig.getArchitectures();
  442. }
  443. addDebugConditionClause (target, "app_abis", debugABIs, releaseABIs);
  444. XmlElement* executable = target->createNewChildElement ("exec");
  445. executable->setAttribute ("executable", "${ndk.dir}/ndk-build");
  446. executable->setAttribute ("dir", "${basedir}");
  447. executable->setAttribute ("failonerror", "true");
  448. executable->createNewChildElement ("arg")->setAttribute ("value", "--jobs=2");
  449. executable->createNewChildElement ("arg")->setAttribute ("value", "CONFIG=${makefileConfig}");
  450. executable->createNewChildElement ("arg")->setAttribute ("value", "${ndkDebugValue}");
  451. executable->createNewChildElement ("arg")->setAttribute ("value", "APP_ABI=${app_abis}");
  452. target->createNewChildElement ("delete")->setAttribute ("file", "${out.final.file}");
  453. target->createNewChildElement ("delete")->setAttribute ("file", "${out.packaged.file}");
  454. }
  455. proj->createNewChildElement ("import")->setAttribute ("file", "${sdk.dir}/tools/ant/build.xml");
  456. return proj;
  457. }
  458. void addDebugConditionClause (XmlElement* target, const String& property,
  459. const String& debugValue, const String& releaseValue) const
  460. {
  461. XmlElement* condition = target->createNewChildElement ("condition");
  462. condition->setAttribute ("property", property);
  463. condition->setAttribute ("value", debugValue);
  464. condition->setAttribute ("else", releaseValue);
  465. XmlElement* equals = condition->createNewChildElement ("equals");
  466. equals->setAttribute ("arg1", "${ant.project.invoked-targets}");
  467. equals->setAttribute ("arg2", "debug");
  468. }
  469. String getAppPlatform() const
  470. {
  471. int ndkVersion = getMinimumSDKVersionString().getIntValue();
  472. if (ndkVersion == 9)
  473. ndkVersion = 10; // (doesn't seem to be a version '9')
  474. return "android-" + String (ndkVersion);
  475. }
  476. void writeProjectPropertiesFile (const File& file) const
  477. {
  478. MemoryOutputStream mo;
  479. mo << "# This file is used to override default values used by the Ant build system." << newLine
  480. << "# It is automatically generated - DO NOT EDIT IT or your changes will be lost!." << newLine
  481. << newLine
  482. << "target=" << getAppPlatform() << newLine
  483. << newLine;
  484. overwriteFileIfDifferentOrThrow (file, mo);
  485. }
  486. void writeLocalPropertiesFile (const File& file) const
  487. {
  488. MemoryOutputStream mo;
  489. mo << "# This file is used to override default values used by the Ant build system." << newLine
  490. << "# It is automatically generated by the Introjucer - DO NOT EDIT IT or your changes will be lost!." << newLine
  491. << newLine
  492. << "sdk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getSDKPathString())) << newLine
  493. << "ndk.dir=" << escapeSpaces (replacePreprocessorDefs (getAllPreprocessorDefs(), getNDKPathString())) << newLine
  494. << "key.store=" << getKeyStoreString() << newLine
  495. << "key.alias=" << getKeyAliasString() << newLine
  496. << "key.store.password=" << getKeyStorePassString() << newLine
  497. << "key.alias.password=" << getKeyAliasPassString() << newLine
  498. << newLine;
  499. overwriteFileIfDifferentOrThrow (file, mo);
  500. }
  501. void writeIcon (const File& file, const Image& im) const
  502. {
  503. if (im.isValid())
  504. {
  505. createDirectoryOrThrow (file.getParentDirectory());
  506. PNGImageFormat png;
  507. MemoryOutputStream mo;
  508. if (! png.writeImageToStream (im, mo))
  509. throw SaveError ("Can't generate Android icon file");
  510. overwriteFileIfDifferentOrThrow (file, mo);
  511. }
  512. }
  513. void writeStringsFile (const File& file) const
  514. {
  515. XmlElement strings ("resources");
  516. XmlElement* name = strings.createNewChildElement ("string");
  517. name->setAttribute ("name", "app_name");
  518. name->addTextElement (projectName);
  519. writeXmlOrThrow (strings, file, "utf-8", 100);
  520. }
  521. //==============================================================================
  522. JUCE_DECLARE_NON_COPYABLE (AndroidProjectExporter);
  523. };
  524. #endif // __JUCER_PROJECTEXPORT_ANDROID_JUCEHEADER__