Skip to content

Commit 0fe7f50

Browse files
committed
target SDK is hard-coded, removed SDK menu
1 parent ecde6e8 commit 0fe7f50

File tree

7 files changed

+84
-78
lines changed

7 files changed

+84
-78
lines changed

src/processing/mode/android/AVD.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class AVD {
7979
/** Default virtual device used by Processing. */
8080
static public final AVD defaultAVD =
8181
new AVD("Processing-0" + Base.getRevision(),
82-
"android-" + AndroidBuild.sdkVersion);
82+
AndroidBuild.target_platform);
8383
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
8484

8585
public AVD(final String name, final String target) {
@@ -203,7 +203,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
203203
}
204204
} catch (InterruptedException e) {}
205205

206-
if (preferredAbi.get(AndroidBuild.sdkVersion) == null) {
206+
if (preferredAbi.get(AndroidBuild.target_api_level) == null) {
207207
return false;
208208
}
209209

@@ -214,7 +214,7 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
214214
"-t", target,
215215
"-c", DEFAULT_SDCARD_SIZE,
216216
"-s", DEFAULT_SKIN,
217-
"--abi", preferredAbi.get(AndroidBuild.sdkVersion)
217+
"--abi", preferredAbi.get(AndroidBuild.target_api_level)
218218
};
219219

220220
// Set the list to null so that exists() will check again
@@ -267,7 +267,7 @@ static public boolean ensureProperAVD(final AndroidSDK sdk) {
267267
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
268268
Messages.showWarningTiered("Android Error", AVD_CREATE_PRIMARY,
269269
String.format(AVD_CREATE_SECONDARY,
270-
AndroidBuild.sdkVersion), null);
270+
AndroidBuild.target_api_level), null);
271271
}
272272
return false;
273273
}

src/processing/mode/android/AndroidBuild.java

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,39 @@
3939
import processing.app.exec.ProcessResult;
4040
import processing.core.PApplet;
4141
import processing.mode.java.JavaBuild;
42-
import processing.mode.java.preproc.SurfaceInfo;
43-
4442
import java.io.*;
4543
import java.security.Permission;
4644

47-
4845
class AndroidBuild extends JavaBuild {
4946
static public final int FRAGMENT = 0;
5047
static public final int WALLPAPER = 1;
5148
static public final int WATCHFACE = 2;
5249
static public final int CARDBOARD = 3;
5350

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
5652
// 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%:
5959
// http://developer.android.com/about/dashboards/index.html
60-
// With 17, we have getRealSize and getRealMetrics:
60+
// because 17 give us getRealSize and getRealMetrics:
6161
// http://developer.android.com/reference/android/view/Display.html#getRealSize(android.graphics.Point)
6262
// 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)
6868

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;
7273

73-
static int publishOption = FRAGMENT;
74+
static int appComponent = FRAGMENT;
7475
static boolean forceNewManifest = false;
7576

7677
private final AndroidSDK sdk;
@@ -95,21 +96,21 @@ public AndroidBuild(final Sketch sketch, final AndroidMode mode) {
9596
}
9697

9798
public static void setPublishOption(int opt, Sketch sketch) {
98-
if (publishOption != opt) {
99-
publishOption = opt;
99+
if (appComponent != opt) {
100+
appComponent = opt;
100101
forceNewManifest = true;
101102
} else {
102103
forceNewManifest = false;
103104
}
104105
}
105106

106107
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);
113114
}
114115

115116
/**
@@ -173,7 +174,7 @@ public File createProject() throws IOException, SketchException {
173174
}
174175

175176
manifest = new Manifest(sketch);
176-
manifest.setSdkTarget(sdkVersion);
177+
manifest.setSdkTarget(target_api_level);
177178
forceNewManifest = false;
178179

179180
// grab code from current editing window (GUI only)
@@ -220,7 +221,7 @@ public File createProject() throws IOException, SketchException {
220221
copyLibraries(libsFolder, assetsFolder);
221222
copyCodeFolder(libsFolder);
222223

223-
if (publishOption == WATCHFACE) {
224+
if (appComponent == WATCHFACE) {
224225
// TODO: temporary hack until I find a better way to include the wearable aar
225226
// package included in the SDK:
226227

@@ -229,7 +230,7 @@ public File createProject() throws IOException, SketchException {
229230
Util.copyFile(wearJarFile, new File(libsFolder, "wearable-1.3.0-classes.jar"));
230231
}
231232

232-
if (publishOption == CARDBOARD) {
233+
if (appComponent == CARDBOARD) {
233234
// TODO: temporary hack until I find a better way to include the cardboard aar
234235
// packages included in the cardboard SDK:
235236

@@ -279,16 +280,14 @@ public File createProject() throws IOException, SketchException {
279280
// System.out.println("API: " + api);
280281
}
281282

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)) {
284285
targetID = id;
285286
break;
286287
}
287288
}
288289
} catch (InterruptedException e) {}
289290

290-
System.out.println("TARGET ID: " + targetID);
291-
292291
////////////////////////////////////////////////////////////////////////
293292
// third step: create library projects
294293
boolean audioRes = createLibraryProject("cardboard_audio", targetID,
@@ -773,13 +772,13 @@ void antBuildProblems(String outPile, String errPile) throws SketchException {
773772

774773
// Try to parse anything else we might know about
775774
for (final String line : errLines) {
776-
if (line.contains("Unable to resolve target '" + sdkTarget + "'")) {
775+
if (line.contains("Unable to resolve target '" + target_platform + "'")) {
777776
System.err.println("Use the Android SDK Manager (under the Android");
778777
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 + ")");
781780
skex = new SketchException("Please install the SDK platform and " +
782-
"Google APIs for API " + sdkVersion);
781+
"Google APIs for API " + target_api_level);
783782
}
784783
}
785784
// Stack trace is not relevant, just the message.
@@ -925,7 +924,7 @@ private void writeBuildXML(final File file, final String projectName) {
925924

926925
private void writeProjectProps(final File file) {
927926
final PrintWriter writer = PApplet.createWriter(file);
928-
writer.println("target=" + sdkTarget);
927+
writer.println("target=" + target_platform);
929928
writer.println();
930929
// http://stackoverflow.com/questions/4821043/includeantruntime-was-not-set-for-android-ant-script
931930
writer.println("# Suppress the javac task warnings about \"includeAntRuntime\"");
@@ -964,7 +963,7 @@ private void writeRes(File resFolder,
964963
File mainActivityLayoutFile = new File(layoutFolder, "main.xml");
965964
writeResLayoutMainActivity(mainActivityLayoutFile);
966965

967-
if (publishOption == WALLPAPER) {
966+
if (appComponent == WALLPAPER) {
968967
File xmlFolder = mkdirs(resFolder, "xml");
969968
File mainServiceWallpaperFile = new File(xmlFolder, "wallpaper.xml");
970969
writeResXMLWallpaper(mainServiceWallpaperFile);
@@ -1051,7 +1050,7 @@ private void writeRes(File resFolder,
10511050
}
10521051

10531052

1054-
if (publishOption == WATCHFACE) {
1053+
if (appComponent == WATCHFACE) {
10551054
File xmlFolder = mkdirs(resFolder, "xml");
10561055
File mainServiceWatchFaceFile = new File(xmlFolder, "watch_face.xml");
10571056
writeResXMLWatchFace(mainServiceWatchFaceFile);
@@ -1126,17 +1125,17 @@ private File mkdirs(final File parent, final String name) throws SketchException
11261125

11271126

11281127
private void writeMainClass(final File srcDirectory, String renderer) {
1129-
if (publishOption == FRAGMENT) {
1128+
if (appComponent == FRAGMENT) {
11301129
writeFragmentActivity(srcDirectory);
1131-
} else if (publishOption == WALLPAPER) {
1130+
} else if (appComponent == WALLPAPER) {
11321131
writeWallpaperService(srcDirectory);
1133-
} else if (publishOption == WATCHFACE) {
1132+
} else if (appComponent == WATCHFACE) {
11341133
if (renderer != null && (renderer.equals("P2D") || renderer.equals("P3D"))) {
11351134
writeWatchFaceGLESService(srcDirectory);
11361135
} else {
11371136
writeWatchFaceCanvasService(srcDirectory);
11381137
}
1139-
} else if (publishOption == CARDBOARD) {
1138+
} else if (appComponent == CARDBOARD) {
11401139
writeCardboardActivity(srcDirectory);
11411140
}
11421141
}

src/processing/mode/android/AndroidEditor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.awt.event.ActionListener;
4545
import java.io.File;
4646
import java.io.IOException;
47-
import java.util.ArrayList;
4847
import java.util.TimerTask;
4948

5049

@@ -79,7 +78,7 @@ public UpdateDeviceListTask(JMenu deviceMenu) {
7978
public void run() {
8079
if (androidMode == null || androidMode.getSDK() == null) return;
8180

82-
if (AndroidBuild.publishOption == AndroidBuild.WATCHFACE) {
81+
if (AndroidBuild.appComponent == AndroidBuild.WATCHFACE) {
8382
Devices.enableBlueToothDebugging();
8483
}
8584

@@ -297,6 +296,7 @@ public void actionPerformed(ActionEvent e) {
297296

298297
menu.addSeparator();
299298

299+
/*
300300
// TODO: The SDK selection menu will be removed once app publishing is fully
301301
// functional: correct minimum SDK level can be inferred from app type
302302
// (fragment, wallpaper, etc), and target SDK from the highest available in
@@ -322,8 +322,9 @@ public void run() {
322322
}.start();
323323
324324
menu.add(sdkMenu);
325-
325+
326326
menu.addSeparator();
327+
*/
327328

328329
item = new JMenuItem("SDK Manager");
329330
item.addActionListener(new ActionListener() {
@@ -359,6 +360,7 @@ public void actionPerformed(ActionEvent e) {
359360
return menu;
360361
}
361362

363+
/*
362364
private void updateSdkMenu(final JMenu sdkMenu) {
363365
try {
364366
ArrayList<AndroidSDK.SDKTarget> targets = androidMode.getSDK().getAvailableSdkTargets();
@@ -394,7 +396,7 @@ private void updateSdkMenu(final JMenu sdkMenu) {
394396
item.addChangeListener(new ChangeListener() {
395397
@Override
396398
public void stateChanged(ChangeEvent e) {
397-
if (target.name.equals(AndroidBuild.sdkName)) item.setState(true);
399+
if (target.name.equals(AndroidBuild.target_sdk_version)) item.setState(true);
398400
else item.setState(false);
399401
}
400402
});
@@ -423,7 +425,7 @@ public void actionPerformed(ActionEvent e) {
423425
e.printStackTrace();
424426
}
425427
}
426-
428+
*/
427429

428430
/**
429431
* Uses the main help menu, and adds a few extra options. If/when there's

src/processing/mode/android/AndroidMode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ public String getSearchPath() {
200200

201201
String path = sdk.getSdkFolder().getAbsolutePath() + File.separator +
202202
"platforms" + File.separator + "android-";
203-
String ver = AndroidBuild.sdkVersion;
204-
String name = AndroidBuild.sdkName;
205-
String androidJarPath = path + ver + File.separator + "android.jar";
203+
String level = AndroidBuild.target_api_level;
204+
String name = AndroidBuild.target_sdk_version;
205+
String androidJarPath = path + level + File.separator + "android.jar";
206206
if (!new File(androidJarPath).exists()) {
207207
// Try again using SDK name, I have seen the SDK stored as platforms/android-x.y.z
208208
androidJarPath = path + name + File.separator + "android.jar";

src/processing/mode/android/AndroidSDK.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AndroidSDK {
4444
private final File folder;
4545
private final File tools;
4646
private final File platforms;
47+
private final File targetPlatform;
4748
private final File platformTools;
4849
private final File androidTool;
4950

@@ -59,7 +60,8 @@ class AndroidSDK {
5960
"If you want to download the SDK manually, you can visit <br>"+
6061
"http://developer.android.com/sdk/installing/index.html <br>" +
6162
"and select the stand-alone SDK tools. Make sure to install <br>"+
62-
"the SDK platform for API 21 (Android 5.0) or higher.";
63+
"the SDK platform for Android " + AndroidBuild.target_sdk_version +
64+
" (API level " + AndroidBuild.target_api_level + ") or higher.";
6365

6466
private static final String SELECT_ANDROID_SDK_FOLDER =
6567
"Choose the location of the Android SDK";
@@ -84,6 +86,12 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
8486
if (!platforms.exists()) {
8587
throw new BadSDKException("There is no platforms folder in " + folder);
8688
}
89+
90+
targetPlatform = new File(platforms, AndroidBuild.target_platform);
91+
if (!targetPlatform.exists()) {
92+
throw new BadSDKException("There is no Android " +
93+
AndroidBuild.target_sdk_version + " in " + platforms.getAbsolutePath());
94+
}
8795

8896
androidTool = findAndroidTool(tools);
8997

0 commit comments

Comments
 (0)