37
37
38
38
import java .io .*;
39
39
import java .util .HashMap ;
40
+ import java .util .Properties ;
40
41
41
42
/**
42
43
* Class with all the infrastructure needed to build a sketch in the Android
@@ -53,71 +54,20 @@ class AndroidBuild extends JavaBuild {
53
54
static public final int AR = 4 ;
54
55
55
56
// Minimum SDK's API levels required for each component:
56
- static public final String MIN_SDK_APP = "17" ; // Android 4.2
57
- static public final String MIN_SDK_WALLPAPER = "17" ; // Android 4.2
58
- static public final String MIN_SDK_VR = "19" ; // Android 4.4
59
- static public final String MIN_SDK_AR = "24" ; // Android 7.0.0
60
- static public final String MIN_SDK_WATCHFACE = "25" ; // Android 7.1.1
57
+ static public String MIN_SDK_APP ;
58
+ static public String MIN_SDK_WALLPAPER ;
59
+ static public String MIN_SDK_VR ;
60
+ static public String MIN_SDK_AR ;
61
+ static public String MIN_SDK_WATCHFACE ;
61
62
62
- // Target SDK is stored in the preferences file.
63
+ // Versions of all required dependencies
63
64
static public String TARGET_SDK ;
64
65
static public String TARGET_PLATFORM ;
65
- static {
66
- TARGET_SDK = Preferences .get ("android.sdk.target" );
67
- if (TARGET_SDK == null || PApplet .parseInt (TARGET_SDK ) < 26 ) {
68
- TARGET_SDK = "26" ;
69
- Preferences .set ("android.sdk.target" , TARGET_SDK );
70
- }
71
- TARGET_PLATFORM = "android-" + TARGET_SDK ;
72
- }
73
-
74
- // Versions of support, play services, wear and VR in use, also stored in
75
- // preferences file so they can be changed without having to rebuilt/reinstall
76
- // the mode.
77
66
static public String SUPPORT_VER ;
78
- static {
79
- SUPPORT_VER = Preferences .get ("android.sdk.support" );
80
- if (SUPPORT_VER == null || !versionCheck (SUPPORT_VER , "26.0.2" )) {
81
- SUPPORT_VER = "26.0.2" ;
82
- Preferences .set ("android.sdk.support" , SUPPORT_VER );
83
- }
84
- }
85
-
86
67
static public String PLAY_SERVICES_VER ;
87
- static {
88
- PLAY_SERVICES_VER = Preferences .get ("android.sdk.play_services" );
89
- if (PLAY_SERVICES_VER == null || !versionCheck (PLAY_SERVICES_VER , "11.0.4" )) {
90
- PLAY_SERVICES_VER = "11.0.4" ;
91
- Preferences .set ("android.sdk.play_services" , PLAY_SERVICES_VER );
92
- }
93
- }
94
-
95
68
static public String WEAR_VER ;
96
- static {
97
- WEAR_VER = Preferences .get ("android.sdk.wear" );
98
- if (WEAR_VER == null || !versionCheck (WEAR_VER , "2.1.0" )) {
99
- WEAR_VER = "2.1.0" ;
100
- Preferences .set ("android.sdk.wear" , WEAR_VER );
101
- }
102
- }
103
-
104
69
static public String GVR_VER ;
105
- static {
106
- GVR_VER = Preferences .get ("android.sdk.gvr" );
107
- if (GVR_VER == null || !versionCheck (GVR_VER , "1.150.0" )) {
108
- GVR_VER = "1.150.0" ;
109
- Preferences .set ("android.sdk.gvr" , GVR_VER );
110
- }
111
- }
112
-
113
70
static public String GAR_VER ;
114
- static {
115
- GAR_VER = Preferences .get ("android.sdk.ar" );
116
- if (GAR_VER == null ) {
117
- GAR_VER = "1.2.0" ;
118
- Preferences .set ("android.sdk.ar" , GAR_VER );
119
- }
120
- }
121
71
122
72
// Main activity or service
123
73
static private final String APP_ACTIVITY_TEMPLATE = "AppActivity.java.tmpl" ;
@@ -375,7 +325,7 @@ private void createAppModule(String moduleName)
375
325
File appBuildFile = new File (moduleFolder , "build.gradle" );
376
326
HashMap <String , String > replaceMap = new HashMap <String , String >();
377
327
replaceMap .put ("@@tools_folder@@" , Base .getToolsFolder ().getPath ().replace ('\\' , '/' ));
378
- replaceMap .put ("@@target_platform@@" , sdk . getTargetPlatform (). getPath (). replace ( '\\' , '/' ) );
328
+ replaceMap .put ("@@target_platform@@" , TARGET_SDK );
379
329
replaceMap .put ("@@package_name@@" , getPackageName ());
380
330
replaceMap .put ("@@min_sdk@@" , minSdk );
381
331
replaceMap .put ("@@target_sdk@@" , TARGET_SDK );
@@ -825,9 +775,9 @@ private void copyImportedLibs(final File libsFolder,
825
775
for (File exportFile : library .getAndroidExports ()) {
826
776
String exportName = exportFile .getName ();
827
777
828
- // Skip the GVR and ARCore jars, because the gradle will resolve the dependencies
829
- if (appComponent == VR && exportName .toLowerCase ().startsWith ("sdk- " )) continue ;
830
- if (appComponent == AR && exportName .toLowerCase ().startsWith ("core- " )) continue ;
778
+ // Skip the GVR and ARCore jars, because gradle will resolve the dependencies
779
+ if (appComponent == VR && exportName .toLowerCase ().startsWith ("sdk" )) continue ;
780
+ if (appComponent == AR && exportName .toLowerCase ().startsWith ("core" )) continue ;
831
781
832
782
if (!exportFile .exists ()) {
833
783
System .err .println (AndroidMode .getTextString ("android_build.error.export_file_does_not_exist" , exportFile .getName ()));
@@ -935,6 +885,73 @@ private File createExportFolder(String name) throws IOException {
935
885
}
936
886
937
887
888
+ static public void initVersions (File file ) {
889
+ InputStream input ;
890
+ try {
891
+ input = new FileInputStream (file );
892
+ Properties props = new Properties ();
893
+ props .load (input );
894
+
895
+ MIN_SDK_APP = props .getProperty ("android-min-app" );
896
+ MIN_SDK_WALLPAPER = props .getProperty ("android-min-wallpaper" );
897
+ MIN_SDK_VR = props .getProperty ("android-min-vr" );
898
+ MIN_SDK_AR = props .getProperty ("android-min-ar" );
899
+ MIN_SDK_WATCHFACE = props .getProperty ("android-min-wear" );
900
+
901
+ // Versions of the target sdk, support, play services, wear, VR, and AR are stored in
902
+ // preferences file so they can be changed by the user without having to rebuilt/reinstall
903
+ // the mode.
904
+
905
+ TARGET_SDK = Preferences .get ("android.sdk.target" );
906
+ String defTargetSDK = props .getProperty ("android-platform" );
907
+ if (TARGET_SDK == null || PApplet .parseInt (TARGET_SDK ) != PApplet .parseInt (defTargetSDK )) {
908
+ TARGET_SDK = defTargetSDK ;
909
+ Preferences .set ("android.sdk.target" , TARGET_SDK );
910
+ }
911
+ TARGET_PLATFORM = "android-" + TARGET_SDK ;
912
+
913
+ SUPPORT_VER = Preferences .get ("android.sdk.support" );
914
+ String defSupportVer = props .getProperty ("com.android.support%support-v4" );
915
+ if (SUPPORT_VER == null || !versionCheck (SUPPORT_VER , defSupportVer )) {
916
+ SUPPORT_VER = defSupportVer ;
917
+ Preferences .set ("android.sdk.support" , SUPPORT_VER );
918
+ }
919
+
920
+ PLAY_SERVICES_VER = Preferences .get ("android.sdk.play_services" );
921
+ String defPlayServicesVer = props .getProperty ("com.google.android.gms%play-services-wearable" );
922
+ if (PLAY_SERVICES_VER == null || !versionCheck (PLAY_SERVICES_VER , defPlayServicesVer )) {
923
+ PLAY_SERVICES_VER = defPlayServicesVer ;
924
+ Preferences .set ("android.sdk.play_services" , PLAY_SERVICES_VER );
925
+ }
926
+
927
+ WEAR_VER = Preferences .get ("android.sdk.wear" );
928
+ String defWearVer = props .getProperty ("com.google.android.support%wearable" );
929
+ if (WEAR_VER == null || !versionCheck (WEAR_VER , defWearVer )) {
930
+ WEAR_VER = defWearVer ;
931
+ Preferences .set ("android.sdk.wear" , WEAR_VER );
932
+ }
933
+
934
+ GVR_VER = Preferences .get ("android.sdk.gvr" );
935
+ String defVRVer = props .getProperty ("com.google.vr" );
936
+ if (GVR_VER == null || !versionCheck (GVR_VER , defVRVer )) {
937
+ GVR_VER = defVRVer ;
938
+ Preferences .set ("android.sdk.gvr" , GVR_VER );
939
+ }
940
+
941
+ GAR_VER = Preferences .get ("android.sdk.ar" );
942
+ String defARVer = props .getProperty ("com.google.ar" );
943
+ if (GAR_VER == null || !versionCheck (GAR_VER , defARVer )) {
944
+ GAR_VER = defARVer ;
945
+ Preferences .set ("android.sdk.ar" , GAR_VER );
946
+ }
947
+ } catch (FileNotFoundException e ) {
948
+ e .printStackTrace ();
949
+ } catch (IOException e ) {
950
+ e .printStackTrace ();
951
+ }
952
+ }
953
+
954
+
938
955
static private boolean versionCheck (String currentVersion , String minVersion ) {
939
956
String [] currentPieces = currentVersion .split ("\\ ." );
940
957
String [] minPieces = minVersion .split ("\\ ." );
0 commit comments