Skip to content

Commit 1a9ca8c

Browse files
committed
Fix File not serializing correctly on Android 12 and therefore assets not loading after app restart
1 parent a68c9f0 commit 1a9ca8c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.51.4]
5+
6+
### Fixed
7+
- Fixed Assets not loading after second app startup on Android 12
8+
49
## [0.51.3]
510

611
### Added

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
}
3232

3333
project.ext {
34-
sdkVersion='0.51.3'
34+
sdkVersion='0.51.4'
3535
versionCode=1
3636

3737
compileSdkVersion=31

core/src/main/java/io/snabble/sdk/Assets.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private class ApiManifest {
9696
}
9797

9898
private class Asset {
99-
public File file;
99+
public String filePath;
100100
public String hash;
101101

102-
public Asset(File file, String hash) {
103-
this.file = file;
102+
public Asset(String filePath, String hash) {
103+
this.filePath = filePath;
104104
this.hash = hash;
105105
}
106106
}
@@ -127,7 +127,7 @@ public interface Callback {
127127
Assets(Project project) {
128128
this.app = Snabble.getInstance().getApplication();
129129
this.project = project;
130-
this.manifestFile = new File(project.getInternalStorageDirectory(), "assets.json");
130+
this.manifestFile = new File(project.getInternalStorageDirectory(), "assets_v2.json");
131131
this.assetDir = new File(project.getInternalStorageDirectory(), "assets/");
132132
this.assetDir.mkdirs();
133133

@@ -280,7 +280,7 @@ private void downloadAssets(Project project, ApiManifest apiManifest, String non
280280

281281
Logger.d("add " + apiAsset.name);
282282

283-
Asset asset = new Asset(localFile, hash);
283+
Asset asset = new Asset(localFile.getAbsolutePath(), hash);
284284
IOUtils.copy(body.byteStream(), new FileOutputStream(localFile));
285285

286286
Dispatch.mainThread(() -> {
@@ -303,7 +303,8 @@ private void downloadAssets(Project project, ApiManifest apiManifest, String non
303303
if (!hashes.contains(asset.hash)) {
304304
Logger.d("remove " + entry.getKey());
305305

306-
asset.file.delete();
306+
File file = new File(asset.filePath);
307+
file.delete();
307308
removals.add(entry.getKey());
308309
}
309310
}
@@ -414,7 +415,7 @@ private Bitmap getBitmapByType(String name, Type type) {
414415
if (asset != null) {
415416
try {
416417
Logger.d("render %s %s/%s", type.name(), project.getId(), name);
417-
return BitmapFactory.decodeStream(new FileInputStream(asset.file));
418+
return BitmapFactory.decodeStream(new FileInputStream(asset.filePath));
418419
} catch (Exception e) {
419420
Logger.d("could not decode " + name + ": " + e.toString());
420421
return null;
@@ -433,7 +434,7 @@ private Bitmap getBitmapSVG(String name) {
433434
Resources res = app.getResources();
434435
DisplayMetrics dm = res.getDisplayMetrics();
435436

436-
SVG svg = SVG.getFromInputStream(new FileInputStream(asset.file));
437+
SVG svg = SVG.getFromInputStream(new FileInputStream(asset.filePath));
437438
int width = Math.round(svg.getDocumentWidth() * dm.density);
438439
int height = Math.round(svg.getDocumentHeight() * dm.density);
439440

0 commit comments

Comments
 (0)