/
jucer_ProjectExport_Android.h
1801 lines (1402 loc) · 83 KB
/
jucer_ProjectExport_Android.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
//==============================================================================
class AndroidProjectExporter : public ProjectExporter
{
public:
//==============================================================================
bool isXcode() const override { return false; }
bool isVisualStudio() const override { return false; }
bool isCodeBlocks() const override { return false; }
bool isMakefile() const override { return false; }
bool isAndroidStudio() const override { return true; }
bool isCLion() const override { return false; }
bool isAndroid() const override { return true; }
bool isWindows() const override { return false; }
bool isLinux() const override { return false; }
bool isOSX() const override { return false; }
bool isiOS() const override { return false; }
bool usesMMFiles() const override { return false; }
bool canCopeWithDuplicateFiles() override { return false; }
bool supportsUserDefinedConfigurations() const override { return true; }
bool supportsTargetType (ProjectType::Target::Type type) const override
{
switch (type)
{
case ProjectType::Target::GUIApp:
case ProjectType::Target::StaticLibrary:
case ProjectType::Target::DynamicLibrary:
case ProjectType::Target::StandalonePlugIn:
return true;
default:
break;
}
return false;
}
//==============================================================================
void addPlatformSpecificSettingsForProjectType (const ProjectType&) override
{
// no-op.
}
//==============================================================================
void createExporterProperties (PropertyListBuilder& props) override
{
createBaseExporterProperties (props);
createToolchainExporterProperties (props);
createManifestExporterProperties (props);
createLibraryModuleExporterProperties (props);
createCodeSigningExporterProperties (props);
createOtherExporterProperties (props);
}
static const char* getName() { return "Android"; }
static const char* getValueTreeTypeName() { return "ANDROIDSTUDIO"; }
static AndroidProjectExporter* createForSettings (Project& project, const ValueTree& settings)
{
if (settings.hasType (getValueTreeTypeName()))
return new AndroidProjectExporter (project, settings);
return nullptr;
}
//==============================================================================
ValueWithDefault androidJavaLibs, androidAdditionalJavaFolders, androidAdditionalResourceFolders, androidRepositories, androidDependencies, androidScreenOrientation,
androidCustomActivityClass, androidCustomApplicationClass, androidManifestCustomXmlElements, androidVersionCode,
androidMinimumSDK, androidTargetSDK, androidTheme, androidSharedLibraries, androidStaticLibraries, androidExtraAssetsFolder,
androidOboeRepositoryPath, androidInternetNeeded, androidMicNeeded, androidCameraNeeded, androidBluetoothNeeded, androidExternalReadPermission,
androidExternalWritePermission, androidInAppBillingPermission, androidVibratePermission,androidOtherPermissions,
androidEnableRemoteNotifications, androidRemoteNotificationsConfigFile, androidEnableContentSharing, androidKeyStore,
androidKeyStorePass, androidKeyAlias, androidKeyAliasPass, gradleVersion, gradleToolchain, androidPluginVersion;
//==============================================================================
AndroidProjectExporter (Project& p, const ValueTree& t)
: ProjectExporter (p, t),
androidJavaLibs (settings, Ids::androidJavaLibs, getUndoManager()),
androidAdditionalJavaFolders (settings, Ids::androidAdditionalJavaFolders, getUndoManager()),
androidAdditionalResourceFolders (settings, Ids::androidAdditionalResourceFolders, getUndoManager()),
androidRepositories (settings, Ids::androidRepositories, getUndoManager()),
androidDependencies (settings, Ids::androidDependencies, getUndoManager()),
androidScreenOrientation (settings, Ids::androidScreenOrientation, getUndoManager(), "unspecified"),
androidCustomActivityClass (settings, Ids::androidCustomActivityClass, getUndoManager()),
androidCustomApplicationClass (settings, Ids::androidCustomApplicationClass, getUndoManager(), "com.roli.juce.JuceApp"),
androidManifestCustomXmlElements (settings, Ids::androidManifestCustomXmlElements, getUndoManager()),
androidVersionCode (settings, Ids::androidVersionCode, getUndoManager(), "1"),
androidMinimumSDK (settings, Ids::androidMinimumSDK, getUndoManager(), "16"),
androidTargetSDK (settings, Ids::androidTargetSDK, getUndoManager(), "28"),
androidTheme (settings, Ids::androidTheme, getUndoManager()),
androidSharedLibraries (settings, Ids::androidSharedLibraries, getUndoManager()),
androidStaticLibraries (settings, Ids::androidStaticLibraries, getUndoManager()),
androidExtraAssetsFolder (settings, Ids::androidExtraAssetsFolder, getUndoManager()),
androidOboeRepositoryPath (settings, Ids::androidOboeRepositoryPath, getUndoManager()),
androidInternetNeeded (settings, Ids::androidInternetNeeded, getUndoManager(), true),
androidMicNeeded (settings, Ids::microphonePermissionNeeded, getUndoManager(), false),
androidCameraNeeded (settings, Ids::cameraPermissionNeeded, getUndoManager(), false),
androidBluetoothNeeded (settings, Ids::androidBluetoothNeeded, getUndoManager(), true),
androidExternalReadPermission (settings, Ids::androidExternalReadNeeded, getUndoManager(), true),
androidExternalWritePermission (settings, Ids::androidExternalWriteNeeded, getUndoManager(), true),
androidInAppBillingPermission (settings, Ids::androidInAppBilling, getUndoManager(), false),
androidVibratePermission (settings, Ids::androidVibratePermissionNeeded, getUndoManager(), false),
androidOtherPermissions (settings, Ids::androidOtherPermissions, getUndoManager()),
androidEnableRemoteNotifications (settings, Ids::androidEnableRemoteNotifications, getUndoManager(), false),
androidRemoteNotificationsConfigFile (settings, Ids::androidRemoteNotificationsConfigFile, getUndoManager()),
androidEnableContentSharing (settings, Ids::androidEnableContentSharing, getUndoManager(), false),
androidKeyStore (settings, Ids::androidKeyStore, getUndoManager(), "${user.home}/.android/debug.keystore"),
androidKeyStorePass (settings, Ids::androidKeyStorePass, getUndoManager(), "android"),
androidKeyAlias (settings, Ids::androidKeyAlias, getUndoManager(), "androiddebugkey"),
androidKeyAliasPass (settings, Ids::androidKeyAliasPass, getUndoManager(), "android"),
gradleVersion (settings, Ids::gradleVersion, getUndoManager(), "4.10"),
gradleToolchain (settings, Ids::gradleToolchain, getUndoManager(), "clang"),
androidPluginVersion (settings, Ids::androidPluginVersion, getUndoManager(), "3.2.1"),
AndroidExecutable (getAppSettings().getStoredPath (Ids::androidStudioExePath, TargetOS::getThisOS()).get().toString())
{
name = getName();
targetLocationValue.setDefault (getDefaultBuildsRootFolder() + getTargetFolderForExporter (getValueTreeTypeName()));
}
//==============================================================================
void createToolchainExporterProperties (PropertyListBuilder& props)
{
props.add (new TextPropertyComponent (gradleVersion, "Gradle Version", 32, false),
"The version of gradle that is used to build this app (4.10 is fine for JUCE)");
props.add (new TextPropertyComponent (androidPluginVersion, "Android Plug-in Version", 32, false),
"The version of the android build plugin for gradle that is used to build this app");
props.add (new ChoicePropertyComponent (gradleToolchain, "NDK Toolchain",
{ "clang", "gcc" },
{ "clang", "gcc" }),
"The toolchain that gradle should invoke for NDK compilation (variable model.android.ndk.tooclhain in app/build.gradle)");
}
void createLibraryModuleExporterProperties (PropertyListBuilder& props)
{
props.add (new TextPropertyComponent (androidStaticLibraries, "Import Static Library Modules", 8192, true),
"Comma or whitespace delimited list of static libraries (.a) defined in NDK_MODULE_PATH.");
props.add (new TextPropertyComponent (androidSharedLibraries, "Import Shared Library Modules", 8192, true),
"Comma or whitespace delimited list of shared libraries (.so) defined in NDK_MODULE_PATH.");
}
//==============================================================================
bool canLaunchProject() override
{
return AndroidExecutable.exists();
}
bool launchProject() override
{
if (! AndroidExecutable.exists())
{
jassertfalse;
return false;
}
auto targetFolder = getTargetFolder();
// we have to surround the path with extra quotes, otherwise Android Studio
// will choke if there are any space characters in the path.
return AndroidExecutable.startAsProcess ("\"" + targetFolder.getFullPathName() + "\"");
}
//==============================================================================
void create (const OwnedArray<LibraryModule>& modules) const override
{
auto targetFolder = getTargetFolder();
auto appFolder = targetFolder.getChildFile (isLibrary() ? "lib" : "app");
removeOldFiles (targetFolder);
copyExtraResourceFiles();
writeFile (targetFolder, "settings.gradle", isLibrary() ? "include ':lib'" : "include ':app'");
writeFile (targetFolder, "build.gradle", getProjectBuildGradleFileContent());
writeFile (appFolder, "build.gradle", getAppBuildGradleFileContent (modules));
writeFile (targetFolder, "local.properties", getLocalPropertiesFileContent());
writeFile (targetFolder, "gradle/wrapper/gradle-wrapper.properties", getGradleWrapperPropertiesFileContent());
writeBinaryFile (targetFolder, "gradle/wrapper/LICENSE-for-gradlewrapper.txt", BinaryData::LICENSE, BinaryData::LICENSESize);
writeBinaryFile (targetFolder, "gradle/wrapper/gradle-wrapper.jar", BinaryData::gradlewrapper_jar, BinaryData::gradlewrapper_jarSize);
writeBinaryFile (targetFolder, "gradlew", BinaryData::gradlew, BinaryData::gradlewSize);
writeBinaryFile (targetFolder, "gradlew.bat", BinaryData::gradlew_bat, BinaryData::gradlew_batSize);
targetFolder.getChildFile ("gradlew").setExecutePermission (true);
writeAndroidManifest (appFolder);
if (! isLibrary())
{
copyAdditionalJavaLibs (appFolder);
writeStringsXML (targetFolder);
writeAppIcons (targetFolder);
}
writeCmakeFile (appFolder.getChildFile ("CMakeLists.txt"));
auto androidExtraAssetsFolderValue = androidExtraAssetsFolder.get().toString();
if (androidExtraAssetsFolderValue.isNotEmpty())
{
auto extraAssets = getProject().getFile().getParentDirectory().getChildFile (androidExtraAssetsFolderValue);
if (extraAssets.exists() && extraAssets.isDirectory())
{
auto assetsFolder = appFolder.getChildFile ("src/main/assets");
if (assetsFolder.deleteRecursively())
extraAssets.copyDirectoryTo (assetsFolder);
}
}
}
void removeOldFiles (const File& targetFolder) const
{
targetFolder.getChildFile ("app/build").deleteRecursively();
targetFolder.getChildFile ("app/build.gradle").deleteFile();
targetFolder.getChildFile ("gradle").deleteRecursively();
targetFolder.getChildFile ("local.properties").deleteFile();
targetFolder.getChildFile ("settings.gradle").deleteFile();
}
void writeFile (const File& gradleProjectFolder, const String& filePath, const String& fileContent) const
{
MemoryOutputStream outStream;
outStream.setNewLineString ("\n");
outStream << fileContent;
overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
}
void writeBinaryFile (const File& gradleProjectFolder, const String& filePath, const char* binaryData, const int binarySize) const
{
MemoryOutputStream outStream;
outStream.setNewLineString ("\n");
outStream.write (binaryData, static_cast<size_t> (binarySize));
overwriteFileIfDifferentOrThrow (gradleProjectFolder.getChildFile (filePath), outStream);
}
protected:
//==============================================================================
class AndroidBuildConfiguration : public BuildConfiguration
{
public:
AndroidBuildConfiguration (Project& p, const ValueTree& settings, const ProjectExporter& e)
: BuildConfiguration (p, settings, e),
androidArchitectures (config, Ids::androidArchitectures, getUndoManager(), isDebug() ? "armeabi-v7a x86 arm64-v8a x86_64" : ""),
androidBuildConfigRemoteNotifsConfigFile (config, Ids::androidBuildConfigRemoteNotifsConfigFile, getUndoManager()),
androidAdditionalXmlValueResources (config, Ids::androidAdditionalXmlValueResources, getUndoManager()),
androidAdditionalDrawableResources (config, Ids::androidAdditionalDrawableResources, getUndoManager()),
androidAdditionalRawValueResources (config, Ids::androidAdditionalRawValueResources, getUndoManager()),
androidCustomStringXmlElements (config, Ids::androidCustomStringXmlElements, getUndoManager())
{
linkTimeOptimisationValue.setDefault (false);
optimisationLevelValue.setDefault (isDebug() ? gccO0 : gccO3);
}
String getArchitectures() const { return androidArchitectures.get().toString(); }
String getRemoteNotifsConfigFile() const { return androidBuildConfigRemoteNotifsConfigFile.get().toString(); }
String getAdditionalXmlResources() const { return androidAdditionalXmlValueResources.get().toString(); }
String getAdditionalDrawableResources() const { return androidAdditionalDrawableResources.get().toString(); }
String getAdditionalRawResources() const { return androidAdditionalRawValueResources.get().toString();}
String getCustomStringsXml() const { return androidCustomStringXmlElements.get().toString(); }
void createConfigProperties (PropertyListBuilder& props) override
{
addGCCOptimisationProperty (props);
props.add (new TextPropertyComponent (androidArchitectures, "Architectures", 256, false),
"A list of the architectures to build (for a fat binary). Leave empty to build for all possible android architectures.");
props.add (new TextPropertyComponent (androidBuildConfigRemoteNotifsConfigFile.getPropertyAsValue(), "Remote Notifications Config File", 2048, false),
"Path to google-services.json file. This will be the file provided by Firebase when creating a new app in Firebase console. "
"This will override the setting from the main Android exporter node.");
props.add (new TextPropertyComponent (androidAdditionalXmlValueResources, "Extra Android XML Value Resources", 8192, true),
"Paths to additional \"value resource\" files in XML format that should be included in the app (one per line). "
"If you have additional XML resources that should be treated as value resources, add them here.");
props.add (new TextPropertyComponent (androidAdditionalDrawableResources, "Extra Android Drawable Resources", 8192, true),
"Paths to additional \"drawable resource\" directories that should be included in the app (one per line). "
"They will be added to \"res\" directory of Android project. "
"Each path should point to a directory named \"drawable\" or \"drawable-<size>\" where <size> should be "
"something like \"hdpi\", \"ldpi\", \"xxxhdpi\" etc, for instance \"drawable-xhdpi\". "
"Refer to Android Studio documentation for available sizes.");
props.add (new TextPropertyComponent (androidAdditionalRawValueResources, "Extra Android Raw Resources", 8192, true),
"Paths to additional \"raw resource\" files that should be included in the app (one per line). "
"Resource file names must contain only lowercase a-z, 0-9 or underscore.");
props.add (new TextPropertyComponent (androidCustomStringXmlElements, "Custom String Resources", 8192, true),
"Custom XML resources that will be added to string.xml as children of <resources> element. "
"Example: \n<string name=\"value\">text</string>\n"
"<string name2=\"value2\">text2</string>\n");
}
String getProductFlavourNameIdentifier() const
{
return getName().toLowerCase().replaceCharacter (L' ', L'_') + String ("_");
}
String getProductFlavourCMakeIdentifier() const
{
return getName().toUpperCase().replaceCharacter (L' ', L'_');
}
String getModuleLibraryArchName() const override
{
return "${ANDROID_ABI}";
}
ValueWithDefault androidArchitectures, androidBuildConfigRemoteNotifsConfigFile,
androidAdditionalXmlValueResources, androidAdditionalDrawableResources,
androidAdditionalRawValueResources, androidCustomStringXmlElements;
};
BuildConfiguration::Ptr createBuildConfig (const ValueTree& v) const override
{
return *new AndroidBuildConfiguration (project, v, *this);
}
private:
void writeCmakeFile (const File& file) const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << "# Automatically generated makefile, created by the Projucer" << newLine
<< "# Don't edit this file! Your changes will be overwritten when you re-save the Projucer project!" << newLine
<< newLine;
mo << "cmake_minimum_required(VERSION 3.4.1)" << newLine << newLine;
if (! isLibrary())
mo << "SET(BINARY_NAME \"juce_jni\")" << newLine << newLine;
if (project.getConfigFlag ("JUCE_USE_ANDROID_OBOE").get())
{
String oboePath (androidOboeRepositoryPath.get().toString().trim().quoted());
mo << "SET(OBOE_DIR " << oboePath << ")" << newLine << newLine;
mo << "add_subdirectory (${OBOE_DIR} ./oboe)" << newLine << newLine;
}
String cpufeaturesPath ("${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c");
mo << "add_library(\"cpufeatures\" STATIC \"" << cpufeaturesPath << "\")" << newLine
<< "set_source_files_properties(\"" << cpufeaturesPath << "\" PROPERTIES COMPILE_FLAGS \"-Wno-sign-conversion -Wno-gnu-statement-expression\")" << newLine << newLine;
{
auto projectDefines = getEscapedPreprocessorDefs (getProjectPreprocessorDefs());
if (projectDefines.size() > 0)
mo << "add_definitions(" << projectDefines.joinIntoString (" ") << ")" << newLine << newLine;
}
{
mo << "include_directories( AFTER" << newLine;
for (auto& path : extraSearchPaths)
mo << " \"" << escapeDirectoryForCmake (path) << "\"" << newLine;
mo << " \"${ANDROID_NDK}/sources/android/cpufeatures\"" << newLine;
if (project.getConfigFlag ("JUCE_USE_ANDROID_OBOE").get())
mo << " \"${OBOE_DIR}/include\"" << newLine;
mo << ")" << newLine << newLine;
}
auto cfgExtraLinkerFlags = getExtraLinkerFlagsString();
if (cfgExtraLinkerFlags.isNotEmpty())
{
mo << "SET( JUCE_LDFLAGS \"" << cfgExtraLinkerFlags.replace ("\"", "\\\"") << "\")" << newLine;
mo << "SET( CMAKE_SHARED_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} ${JUCE_LDFLAGS}\")" << newLine << newLine;
}
mo << "enable_language(ASM)" << newLine << newLine;
auto userLibraries = StringArray::fromTokens (getExternalLibrariesString(), ";", "");
userLibraries.addArray (androidLibs);
if (getNumConfigurations() > 0)
{
bool first = true;
for (ConstConfigIterator config (*this); config.next();)
{
auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
auto libSearchPaths = cfg.getLibrarySearchPaths();
auto cfgDefines = getConfigPreprocessorDefs (cfg);
auto cfgHeaderPaths = cfg.getHeaderSearchPaths();
auto cfgLibraryPaths = cfg.getLibrarySearchPaths();
if (! isLibrary() && libSearchPaths.size() == 0 && cfgDefines.size() == 0
&& cfgHeaderPaths.size() == 0 && cfgLibraryPaths.size() == 0)
continue;
mo << (first ? "IF" : "ELSEIF") << "(JUCE_BUILD_CONFIGURATION MATCHES \"" << cfg.getProductFlavourCMakeIdentifier() <<"\")" << newLine;
if (isLibrary())
{
mo << " SET(BINARY_NAME \"" << getNativeModuleBinaryName (cfg) << "\")" << newLine;
auto binaryLocation = cfg.getTargetBinaryRelativePathString();
if (binaryLocation.isNotEmpty())
{
auto locationRelativeToCmake = RelativePath (binaryLocation, RelativePath::projectFolder)
.rebased (getProject().getFile().getParentDirectory(),
file.getParentDirectory(), RelativePath::buildTargetFolder);
mo << " SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY \"" << "../../../../" << locationRelativeToCmake.toUnixStyle() << "\")" << newLine;
}
}
writeCmakePathLines (mo, " ", "link_directories(", libSearchPaths);
if (cfgDefines.size() > 0)
mo << " add_definitions(" << getEscapedPreprocessorDefs (cfgDefines).joinIntoString (" ") << ")" << newLine;
writeCmakePathLines (mo, " ", "include_directories( AFTER", cfgHeaderPaths);
if (userLibraries.size() > 0)
{
for (auto& lib : userLibraries)
{
String findLibraryCmd;
findLibraryCmd << "find_library(" << lib.toLowerCase().replaceCharacter (L' ', L'_')
<< " \"" << lib << "\" PATHS";
writeCmakePathLines (mo, " ", findLibraryCmd, cfgLibraryPaths, " NO_CMAKE_FIND_ROOT_PATH)");
}
mo << newLine;
}
if (cfg.isLinkTimeOptimisationEnabled())
{
// There's no MIPS support for LTO
String mipsCondition ("NOT (ANDROID_ABI STREQUAL \"mips\" OR ANDROID_ABI STREQUAL \"mips64\")");
mo << " if(" << mipsCondition << ")" << newLine;
StringArray cmakeVariables ("CMAKE_C_FLAGS", "CMAKE_CXX_FLAGS", "CMAKE_EXE_LINKER_FLAGS");
for (auto& variable : cmakeVariables)
{
auto configVariable = variable + "_" + cfg.getProductFlavourCMakeIdentifier();
mo << " SET(" << configVariable << " \"${" << configVariable << "} -flto\")" << newLine;
}
mo << " ENDIF(" << mipsCondition << ")" << newLine;
}
first = false;
}
if (! first)
{
ProjectExporter::BuildConfiguration::Ptr config (getConfiguration(0));
if (config)
{
if (auto* cfg = dynamic_cast<const AndroidBuildConfiguration*> (config.get()))
{
mo << "ELSE(JUCE_BUILD_CONFIGURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine;
mo << " MESSAGE( FATAL_ERROR \"No matching build-configuration found.\" )" << newLine;
mo << "ENDIF(JUCE_BUILD_CONFIGURATION MATCHES \"" << cfg->getProductFlavourCMakeIdentifier() <<"\")" << newLine << newLine;
}
}
}
}
Array<RelativePath> excludeFromBuild;
Array<std::pair<RelativePath, String>> extraCompilerFlags;
mo << "add_library( ${BINARY_NAME}" << newLine;
mo << newLine;
mo << " " << (getProject().getProjectType().isStaticLibrary() ? "STATIC" : "SHARED") << newLine;
mo << newLine;
addCompileUnits (mo, excludeFromBuild, extraCompilerFlags);
mo << ")" << newLine << newLine;
if (excludeFromBuild.size() > 0)
{
for (auto& exclude : excludeFromBuild)
mo << "set_source_files_properties(\"" << exclude.toUnixStyle() << "\" PROPERTIES HEADER_FILE_ONLY TRUE)" << newLine;
mo << newLine;
}
if (! extraCompilerFlags.isEmpty())
{
for (auto& extra : extraCompilerFlags)
mo << "set_source_files_properties(\"" << extra.first.toUnixStyle() << "\" PROPERTIES COMPILE_FLAGS " << extra.second << " )" << newLine;
mo << newLine;
}
auto libraries = getAndroidLibraries();
if (libraries.size() > 0)
{
for (auto& lib : libraries)
mo << "find_library(" << lib.toLowerCase().replaceCharacter (L' ', L'_') << " \"" << lib << "\")" << newLine;
mo << newLine;
}
libraries.addArray (userLibraries);
mo << "target_link_libraries( ${BINARY_NAME}";
if (libraries.size() > 0)
{
mo << newLine << newLine;
for (auto& lib : libraries)
mo << " ${" << lib.toLowerCase().replaceCharacter (L' ', L'_') << "}" << newLine;
mo << " \"cpufeatures\"" << newLine;
}
if (project.getConfigFlag ("JUCE_USE_ANDROID_OBOE").get())
mo << " \"oboe\"" << newLine;
mo << ")" << newLine;
overwriteFileIfDifferentOrThrow (file, mo);
}
//==============================================================================
String getProjectBuildGradleFileContent() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << "buildscript {" << newLine;
mo << " repositories {" << newLine;
mo << " google()" << newLine;
mo << " jcenter()" << newLine;
mo << " }" << newLine;
mo << " dependencies {" << newLine;
mo << " classpath 'com.android.tools.build:gradle:" << androidPluginVersion.get().toString() << "'" << newLine;
if (androidEnableRemoteNotifications.get())
mo << " classpath 'com.google.gms:google-services:3.1.0'" << newLine;
mo << " }" << newLine;
mo << "}" << newLine;
mo << "" << newLine;
mo << "allprojects {" << newLine;
mo << " repositories {" << newLine;
mo << " google()" << newLine;
mo << " jcenter()" << newLine;
if (androidEnableRemoteNotifications.get())
{
mo << " maven {" << newLine;
mo << " url \"https://maven.google.com\"" << newLine;
mo << " }" << newLine;
}
mo << " }" << newLine;
mo << "}" << newLine;
return mo.toString();
}
//==============================================================================
String getAppBuildGradleFileContent (const OwnedArray<LibraryModule>& modules) const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << "apply plugin: 'com.android." << (isLibrary() ? "library" : "application") << "'" << newLine << newLine;
mo << "android {" << newLine;
mo << " compileSdkVersion " << static_cast<int> (androidTargetSDK.get()) << newLine;
mo << " externalNativeBuild {" << newLine;
mo << " cmake {" << newLine;
mo << " path \"CMakeLists.txt\"" << newLine;
mo << " }" << newLine;
mo << " }" << newLine;
mo << getAndroidSigningConfig() << newLine;
mo << getAndroidDefaultConfig() << newLine;
mo << getAndroidBuildTypes() << newLine;
mo << getAndroidProductFlavours() << newLine;
mo << getAndroidVariantFilter() << newLine;
mo << getAndroidJavaSourceSets (modules) << newLine;
mo << getAndroidRepositories() << newLine;
mo << getAndroidDependencies() << newLine;
mo << getApplyPlugins() << newLine;
mo << "}" << newLine << newLine;
return mo.toString();
}
String getAndroidProductFlavours() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " flavorDimensions \"default\"" << newLine;
mo << " productFlavors {" << newLine;
for (ConstConfigIterator config (*this); config.next();)
{
auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
mo << " " << cfg.getProductFlavourNameIdentifier() << " {" << newLine;
if (cfg.getArchitectures().isNotEmpty())
{
mo << " ndk {" << newLine;
mo << " abiFilters " << toGradleList (StringArray::fromTokens (cfg.getArchitectures(), " ", "")) << newLine;
mo << " }" << newLine;
}
mo << " externalNativeBuild {" << newLine;
mo << " cmake {" << newLine;
if (getProject().getProjectType().isStaticLibrary())
mo << " targets \"" << getNativeModuleBinaryName (cfg) << "\"" << newLine;
mo << " arguments \"-DJUCE_BUILD_CONFIGURATION=" << cfg.getProductFlavourCMakeIdentifier() << "\""
<< ", \"-DCMAKE_CXX_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag() << "\""
<< ", \"-DCMAKE_C_FLAGS_" << (cfg.isDebug() ? "DEBUG" : "RELEASE")
<< "=-O" << cfg.getGCCOptimisationFlag() << "\"" << newLine;
mo << " }" << newLine;
mo << " }" << newLine << newLine;
mo << " dimension \"default\"" << newLine;
mo << " }" << newLine;
}
mo << " }" << newLine;
return mo.toString();
}
String getAndroidSigningConfig() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
auto keyStoreFilePath = androidKeyStore.get().toString().replace ("${user.home}", "${System.properties['user.home']}")
.replace ("/", "${File.separator}");
mo << " signingConfigs {" << newLine;
mo << " juceSigning {" << newLine;
mo << " storeFile file(\"" << keyStoreFilePath << "\")" << newLine;
mo << " storePassword \"" << androidKeyStorePass.get().toString() << "\"" << newLine;
mo << " keyAlias \"" << androidKeyAlias.get().toString() << "\"" << newLine;
mo << " keyPassword \"" << androidKeyAliasPass.get().toString() << "\"" << newLine;
mo << " storeType \"jks\"" << newLine;
mo << " }" << newLine;
mo << " }" << newLine;
return mo.toString();
}
String getAndroidDefaultConfig() const
{
auto bundleIdentifier = project.getBundleIdentifierString().toLowerCase();
auto cmakeDefs = getCmakeDefinitions();
auto cFlags = getProjectCompilerFlags();
auto cxxFlags = getProjectCxxCompilerFlags();
auto minSdkVersion = static_cast<int> (androidMinimumSDK.get());
auto targetSdkVersion = static_cast<int> (androidTargetSDK.get());
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " defaultConfig {" << newLine;
if (! isLibrary())
mo << " applicationId \"" << bundleIdentifier << "\"" << newLine;
mo << " minSdkVersion " << minSdkVersion << newLine;
mo << " targetSdkVersion " << targetSdkVersion << newLine;
mo << " externalNativeBuild {" << newLine;
mo << " cmake {" << newLine;
mo << " arguments " << cmakeDefs.joinIntoString (", ") << newLine;
if (cFlags.size() > 0)
mo << " cFlags " << cFlags.joinIntoString (", ") << newLine;
if (cxxFlags.size() > 0)
mo << " cppFlags " << cxxFlags.joinIntoString (", ") << newLine;
mo << " }" << newLine;
mo << " }" << newLine;
mo << " }" << newLine;
return mo.toString();
}
String getAndroidBuildTypes() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " buildTypes {" << newLine;
int numDebugConfigs = 0;
auto numConfigs = getNumConfigurations();
for (int i = 0; i < numConfigs; ++i)
{
auto config = getConfiguration(i);
if (config->isDebug()) numDebugConfigs++;
if (numDebugConfigs > 1 || ((numConfigs - numDebugConfigs) > 1))
continue;
mo << " " << (config->isDebug() ? "debug" : "release") << " {" << newLine;
mo << " initWith " << (config->isDebug() ? "debug" : "release") << newLine;
mo << " debuggable " << (config->isDebug() ? "true" : "false") << newLine;
mo << " jniDebuggable " << (config->isDebug() ? "true" : "false") << newLine;
mo << " signingConfig signingConfigs.juceSigning" << newLine;
mo << " }" << newLine;
}
mo << " }" << newLine;
return mo.toString();
}
String getAndroidVariantFilter() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " variantFilter { variant ->" << newLine;
mo << " def names = variant.flavors*.name" << newLine;
for (ConstConfigIterator config (*this); config.next();)
{
auto& cfg = dynamic_cast<const AndroidBuildConfiguration&> (*config);
mo << " if (names.contains (\"" << cfg.getProductFlavourNameIdentifier() << "\")" << newLine;
mo << " && variant.buildType.name != \"" << (cfg.isDebug() ? "debug" : "release") << "\") {" << newLine;
mo << " setIgnore(true)" << newLine;
mo << " }" << newLine;
}
mo << " }" << newLine;
return mo.toString();
}
String getAndroidRepositories() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
auto repositories = StringArray::fromLines (androidRepositories.get().toString());
mo << " repositories {" << newLine;
for (auto& r : repositories)
mo << " " << r << newLine;
mo << " }" << newLine;
return mo.toString();
}
String getAndroidDependencies() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " dependencies {" << newLine;
for (auto& d : StringArray::fromLines (androidDependencies.get().toString()))
mo << " " << d << newLine;
for (auto& d : StringArray::fromLines (androidJavaLibs.get().toString()))
mo << " implementation files('libs/" << File (d).getFileName() << "')" << newLine;
if (androidEnableRemoteNotifications.get())
{
mo << " 'com.google.firebase:firebase-core:11.4.0'" << newLine;
mo << " compile 'com.google.firebase:firebase-messaging:11.4.0'" << newLine;
}
mo << " }" << newLine;
return mo.toString();
}
String getApplyPlugins() const
{
MemoryOutputStream mo;
mo.setNewLineString ("\n");
if (androidEnableRemoteNotifications.get())
mo << "apply plugin: 'com.google.gms.google-services'" << newLine;
return mo.toString();
}
void addModuleJavaFolderToSourceSet(StringArray& javaSourceSets, const File& javacore) const
{
if (javacore.isDirectory())
{
auto appFolder = getTargetFolder().getChildFile ("app");
RelativePath relativePath (javacore, appFolder, RelativePath::buildTargetFolder);
javaSourceSets.add (relativePath.toUnixStyle());
}
}
String getAndroidJavaSourceSets (const OwnedArray<LibraryModule>& modules) const
{
auto javaSourceSets = getSourceSetArrayFor (androidAdditionalJavaFolders.get().toString());
auto resourceSets = getSourceSetArrayFor (androidAdditionalResourceFolders.get().toString());
for (auto* module : modules)
{
auto javaFolder = module->getFolder().getChildFile ("native").getChildFile ("javacore");
addModuleJavaFolderToSourceSet (javaSourceSets, javaFolder.getChildFile("init"));
if (! isLibrary())
addModuleJavaFolderToSourceSet (javaSourceSets, javaFolder.getChildFile("app"));
}
MemoryOutputStream mo;
mo.setNewLineString ("\n");
mo << " sourceSets {" << newLine;
mo << getSourceSetStringFor ("main.java.srcDirs", javaSourceSets);
mo << newLine;
mo << getSourceSetStringFor ("main.res.srcDirs", resourceSets);
mo << " }" << newLine;
return mo.toString();
}
StringArray getSourceSetArrayFor (const String& srcDirs) const
{
StringArray sourceSets;
for (auto folder : StringArray::fromLines (srcDirs))
{
if (File::isAbsolutePath (folder))
{
sourceSets.add (folder);
}
else
{
auto appFolder = getTargetFolder().getChildFile ("app");
auto relativePath = RelativePath (folder, RelativePath::projectFolder)
.rebased (getProject().getProjectFolder(), appFolder,
RelativePath::buildTargetFolder);
sourceSets.add (relativePath.toUnixStyle());
}
}
return sourceSets;
}
static String getSourceSetStringFor (const String& type, const StringArray& srcDirs)
{
String s;
s << " " << type << " +=" << newLine;
s << " [";
bool isFirst = true;
for (auto sourceSet : srcDirs)
{
if (! isFirst)
s << "," << newLine << " ";
isFirst = false;
s << "\"" << sourceSet << "\"";
}
s << "]" << newLine;
return replaceLineFeeds (s, "\n");
}
//==============================================================================
String getLocalPropertiesFileContent() const
{
String props;
props << "ndk.dir=" << sanitisePath (getAppSettings().getStoredPath (Ids::androidNDKPath, TargetOS::getThisOS()).get().toString()) << newLine
<< "sdk.dir=" << sanitisePath (getAppSettings().getStoredPath (Ids::androidSDKPath, TargetOS::getThisOS()).get().toString()) << newLine;
return replaceLineFeeds (props, "\n");
}
String getGradleWrapperPropertiesFileContent() const
{
String props;
props << "distributionUrl=https\\://services.gradle.org/distributions/gradle-"
<< gradleVersion.get().toString() << "-all.zip";
return props;
}
//==============================================================================
void createBaseExporterProperties (PropertyListBuilder& props)
{
props.add (new TextPropertyComponent (androidAdditionalJavaFolders, "Java Source code folders", 32768, true),
"Folders inside which additional java source files can be found (one per line). For example, if you "
"are using your own Activity you should place the java files for this into a folder and add the folder "
"path to this field.");
props.add (new TextPropertyComponent (androidAdditionalResourceFolders, "Resource folders", 32768, true),
"Folders inside which additional resource files can be found (one per line). For example, if you "
"want to add your own layout xml files then you should place a layout xml file inside a folder and add "
"the folder path to this field.");
props.add (new TextPropertyComponent (androidJavaLibs, "Java libraries to include", 32768, true),
"Java libs (JAR files) (one per line). These will be copied to app/libs folder and \"implementation files\" "
"dependency will be automatically added to module \"dependencies\" section for each library, so do "
"not add the dependency yourself.");
props.add (new TextPropertyComponent (androidRepositories, "Module Repositories", 32768, true),
"Module repositories (one per line). These will be added to module-level gradle file repositories section. ");
props.add (new TextPropertyComponent (androidDependencies, "Module Dependencies", 32768, true),
"Module dependencies (one per line). These will be added to module-level gradle file \"dependencies\" section. "
"If adding any java libs in \"Java libraries to include\" setting, do not add them here as "
"they will be added automatically.");
props.add (new ChoicePropertyComponent (androidScreenOrientation, "Screen Orientation",
{ "Portrait and Landscape", "Portrait", "Landscape" },
{ "unspecified", "portrait", "landscape" }),
"The screen orientations that this app should support");
props.add (new TextPropertyComponent (androidCustomActivityClass, "Custom Android Activity", 256, false),
"If not empty, specifies the Android Activity class name stored in the app's manifest which "
"should be used instead of Android's default Activity.");
props.add (new TextPropertyComponent (androidCustomApplicationClass, "Custom Android Application", 256, false),
"If not empty, specifies the Android Application class name stored in the app's manifest which "
"should be used instead of JUCE's default JuceApp class. If you specify a custom App then you must "
"call com.roli.juce.Java.initialiseJUCE somewhere in your code before calling any JUCE functions.");
props.add (new TextPropertyComponent (androidVersionCode, "Android Version Code", 32, false),
"An integer value that represents the version of the application code, relative to other versions.");
props.add (new TextPropertyComponent (androidMinimumSDK, "Minimum SDK Version", 32, false),
"The number of the minimum version of the Android SDK that the app requires (must be 16 or higher).");
props.add (new TextPropertyComponent (androidTargetSDK, "Target SDK Version", 32, false),
"The number of the version of the Android SDK that the app is targeting.");
props.add (new TextPropertyComponent (androidExtraAssetsFolder, "Extra Android Assets", 256, false),
"A path to a folder (relative to the project folder) which contains extra android assets.");
}
//==============================================================================
void createManifestExporterProperties (PropertyListBuilder& props)
{
props.add (new TextPropertyComponent (androidOboeRepositoryPath, "Oboe Repository Path", 2048, false),