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.

680 lines
30KB

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