39
39
import processing .app .exec .ProcessResult ;
40
40
import processing .core .PApplet ;
41
41
import processing .mode .java .JavaBuild ;
42
- import processing .mode .java .preproc .SurfaceInfo ;
43
-
44
42
import java .io .*;
45
43
import java .security .Permission ;
46
44
47
-
48
45
class AndroidBuild extends JavaBuild {
49
46
static public final int FRAGMENT = 0 ;
50
47
static public final int WALLPAPER = 1 ;
51
48
static public final int WATCHFACE = 2 ;
52
49
static public final int CARDBOARD = 3 ;
53
50
54
- // TODO: make package parameter in the config file, as well as the SDK version
55
- // to download (latest, specific number)
51
+ // TODO: ask base package name when exporting signed apk
56
52
// static final String basePackage = "changethispackage.beforesubmitting.tothemarket";
57
- // We should start with either 16 (4.1) or 17 (4.2) because combined usage of
58
- // all previous versions is less than 5%:
53
+ static final String basePackage = "processing.test" ;
54
+
55
+ // Minimum SDK levels required for each app component
56
+ // https://source.android.com/source/build-numbers.html
57
+ // We should use 17 (4.2) as minimum for fragment and wallpaper at some point,
58
+ // once combined usage of all previous versions is falls below 5%:
59
59
// http://developer.android.com/about/dashboards/index.html
60
- // With 17, we have getRealSize and getRealMetrics:
60
+ // because 17 give us getRealSize and getRealMetrics:
61
61
// http://developer.android.com/reference/android/view/Display.html#getRealSize(android.graphics.Point)
62
62
// http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics)
63
- static final String basePackage = "processing.test" ;
64
- static public final int min_sdk_fragment = 14 ; // Ice Cream Sandwich
65
- static public final int min_sdk_wallpaper = 14 ;
66
- static public final int min_sdk_watchface = 21 ; // Lillipop
67
- static public final int min_sdk_cardboard = 19 ; // Kitkat
63
+ // which allows us to exactly determine the size of the screen.
64
+ static public final String min_sdk_fragment = "16" ; // Jelly Bean (4.1)
65
+ static public final String min_sdk_wallpaper = "16" ; //
66
+ static public final String min_sdk_cardboard = "19" ; // KitKat (4.4)
67
+ static public final String min_sdk_watchface = "21" ; // Lollipop (5.0)
68
68
69
- static String sdkName = "5.0" ;
70
- static String sdkVersion = "21" ; // Android 5.0 (Lollipop)
71
- static String sdkTarget = "android-" + sdkVersion ;
69
+ // Hard-coded target SDK, no longer user-selected.
70
+ static public final String target_sdk_version = "5.1" ; // Lollipop
71
+ static public final String target_api_level = "22" ;
72
+ static public final String target_platform = "android-" + target_api_level ;
72
73
73
- static int publishOption = FRAGMENT ;
74
+ static int appComponent = FRAGMENT ;
74
75
static boolean forceNewManifest = false ;
75
76
76
77
private final AndroidSDK sdk ;
@@ -95,21 +96,21 @@ public AndroidBuild(final Sketch sketch, final AndroidMode mode) {
95
96
}
96
97
97
98
public static void setPublishOption (int opt , Sketch sketch ) {
98
- if (publishOption != opt ) {
99
- publishOption = opt ;
99
+ if (appComponent != opt ) {
100
+ appComponent = opt ;
100
101
forceNewManifest = true ;
101
102
} else {
102
103
forceNewManifest = false ;
103
104
}
104
105
}
105
106
106
107
public static void setSdkTarget (AndroidSDK .SDKTarget target , Sketch sketch ) {
107
- sdkName = target .name ;
108
- sdkVersion = Integer .toString (target .version );
109
- sdkTarget = "android-" + sdkVersion ;
110
-
111
- Preferences .set ("android.sdk.version" , sdkVersion );
112
- Preferences .set ("android.sdk.name" , target .name );
108
+ // sdkName = target.name;
109
+ // sdkVersion = Integer.toString(target.version);
110
+ // sdkTarget = "android-" + sdkVersion;
111
+ //
112
+ // Preferences.set("android.sdk.version", target_ );
113
+ // Preferences.set("android.sdk.name", target.name);
113
114
}
114
115
115
116
/**
@@ -173,7 +174,7 @@ public File createProject() throws IOException, SketchException {
173
174
}
174
175
175
176
manifest = new Manifest (sketch );
176
- manifest .setSdkTarget (sdkVersion );
177
+ manifest .setSdkTarget (target_api_level );
177
178
forceNewManifest = false ;
178
179
179
180
// grab code from current editing window (GUI only)
@@ -220,7 +221,7 @@ public File createProject() throws IOException, SketchException {
220
221
copyLibraries (libsFolder , assetsFolder );
221
222
copyCodeFolder (libsFolder );
222
223
223
- if (publishOption == WATCHFACE ) {
224
+ if (appComponent == WATCHFACE ) {
224
225
// TODO: temporary hack until I find a better way to include the wearable aar
225
226
// package included in the SDK:
226
227
@@ -229,7 +230,7 @@ public File createProject() throws IOException, SketchException {
229
230
Util .copyFile (wearJarFile , new File (libsFolder , "wearable-1.3.0-classes.jar" ));
230
231
}
231
232
232
- if (publishOption == CARDBOARD ) {
233
+ if (appComponent == CARDBOARD ) {
233
234
// TODO: temporary hack until I find a better way to include the cardboard aar
234
235
// packages included in the cardboard SDK:
235
236
@@ -279,16 +280,14 @@ public File createProject() throws IOException, SketchException {
279
280
// System.out.println("API: " + api);
280
281
}
281
282
282
- if (platform != null && platform .equals (sdkTarget ) &&
283
- api != null && api .equals (sdkVersion )) {
283
+ if (platform != null && platform .equals (target_platform ) &&
284
+ api != null && api .equals (target_api_level )) {
284
285
targetID = id ;
285
286
break ;
286
287
}
287
288
}
288
289
} catch (InterruptedException e ) {}
289
290
290
- System .out .println ("TARGET ID: " + targetID );
291
-
292
291
////////////////////////////////////////////////////////////////////////
293
292
// third step: create library projects
294
293
boolean audioRes = createLibraryProject ("cardboard_audio" , targetID ,
@@ -773,13 +772,13 @@ void antBuildProblems(String outPile, String errPile) throws SketchException {
773
772
774
773
// Try to parse anything else we might know about
775
774
for (final String line : errLines ) {
776
- if (line .contains ("Unable to resolve target '" + sdkTarget + "'" )) {
775
+ if (line .contains ("Unable to resolve target '" + target_platform + "'" )) {
777
776
System .err .println ("Use the Android SDK Manager (under the Android" );
778
777
System .err .println ("menu) to install the SDK platform and " );
779
- System .err .println ("Google APIs for Android " + sdkName +
780
- " (API " + sdkVersion + ")" );
778
+ System .err .println ("Google APIs for Android " + target_sdk_version +
779
+ " (API " + target_api_level + ")" );
781
780
skex = new SketchException ("Please install the SDK platform and " +
782
- "Google APIs for API " + sdkVersion );
781
+ "Google APIs for API " + target_api_level );
783
782
}
784
783
}
785
784
// Stack trace is not relevant, just the message.
@@ -925,7 +924,7 @@ private void writeBuildXML(final File file, final String projectName) {
925
924
926
925
private void writeProjectProps (final File file ) {
927
926
final PrintWriter writer = PApplet .createWriter (file );
928
- writer .println ("target=" + sdkTarget );
927
+ writer .println ("target=" + target_platform );
929
928
writer .println ();
930
929
// http://stackoverflow.com/questions/4821043/includeantruntime-was-not-set-for-android-ant-script
931
930
writer .println ("# Suppress the javac task warnings about \" includeAntRuntime\" " );
@@ -964,7 +963,7 @@ private void writeRes(File resFolder,
964
963
File mainActivityLayoutFile = new File (layoutFolder , "main.xml" );
965
964
writeResLayoutMainActivity (mainActivityLayoutFile );
966
965
967
- if (publishOption == WALLPAPER ) {
966
+ if (appComponent == WALLPAPER ) {
968
967
File xmlFolder = mkdirs (resFolder , "xml" );
969
968
File mainServiceWallpaperFile = new File (xmlFolder , "wallpaper.xml" );
970
969
writeResXMLWallpaper (mainServiceWallpaperFile );
@@ -1051,7 +1050,7 @@ private void writeRes(File resFolder,
1051
1050
}
1052
1051
1053
1052
1054
- if (publishOption == WATCHFACE ) {
1053
+ if (appComponent == WATCHFACE ) {
1055
1054
File xmlFolder = mkdirs (resFolder , "xml" );
1056
1055
File mainServiceWatchFaceFile = new File (xmlFolder , "watch_face.xml" );
1057
1056
writeResXMLWatchFace (mainServiceWatchFaceFile );
@@ -1126,17 +1125,17 @@ private File mkdirs(final File parent, final String name) throws SketchException
1126
1125
1127
1126
1128
1127
private void writeMainClass (final File srcDirectory , String renderer ) {
1129
- if (publishOption == FRAGMENT ) {
1128
+ if (appComponent == FRAGMENT ) {
1130
1129
writeFragmentActivity (srcDirectory );
1131
- } else if (publishOption == WALLPAPER ) {
1130
+ } else if (appComponent == WALLPAPER ) {
1132
1131
writeWallpaperService (srcDirectory );
1133
- } else if (publishOption == WATCHFACE ) {
1132
+ } else if (appComponent == WATCHFACE ) {
1134
1133
if (renderer != null && (renderer .equals ("P2D" ) || renderer .equals ("P3D" ))) {
1135
1134
writeWatchFaceGLESService (srcDirectory );
1136
1135
} else {
1137
1136
writeWatchFaceCanvasService (srcDirectory );
1138
1137
}
1139
- } else if (publishOption == CARDBOARD ) {
1138
+ } else if (appComponent == CARDBOARD ) {
1140
1139
writeCardboardActivity (srcDirectory );
1141
1140
}
1142
1141
}
0 commit comments