mirror of
https://github.com/fr3ts0n/AndrOBD.git
synced 2026-08-04 08:52:37 -04:00
First real device test on a signed release build crashed on every
launch: NullPointerException in ObdProt's static initializer, from
EcuDataItems.loadFromResource() calling
getClass().getResource("prot/obd/res/pids.csv").openStream() on a null
InputStream.
Root cause: R8's default class repackaging moved EcuDataItems into the
root package. getResource() with a relative (non-"/"-prefixed) path
resolves against the class's own package at runtime, so once the class
moved, the lookup no longer matched where the resource actually lives
in the APK (confirmed present, unchanged, in both the debug and
release APKs - this was never a resource-shrinking problem). -keeppackagenames
stops the repackaging without giving up class/member renaming or code
shrinking.
Also corrected the existing ProcessVar keep rule's comment: the actual
live reflection risk is Java serialization via the Save/Load menu
items (FileHelper.saveData/loadData), not PvXMLHandler's
Class.forName() path, which turns out to be dead code on Android
(only reachable from its own desktop-only main()).
Verified on a real device (Pixel 10): signed with the debug keystore
for local testing, installed, launched clean - no crash, confirmed via
a clean logcat (zero FATAL EXCEPTION on a fresh launch), where the
previous build crashed on every single launch.
32 lines
1.6 KiB
Prolog
32 lines
1.6 KiB
Prolog
# Add project specific ProGuard rules here.
|
|
# For more details, see
|
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
|
|
# The Save/Load menu items (MainActivity -> FileHelper.saveData/loadData)
|
|
# serialize live ProcessVar objects (ObdProt.PidPvs/VidPvs/tCodes,
|
|
# MainActivity.mPluginPvs) with plain Java serialization (ObjectOutputStream).
|
|
# Deserialization matches by class name, so keep the whole hierarchy -
|
|
# including any future subclasses - and the no-arg constructor, or a
|
|
# previously-saved file fails to load after R8 renames these classes.
|
|
# (PvXMLHandler's own reflective Class.forName() load path is dead code on
|
|
# Android - only reachable from its own standalone main(), never called by
|
|
# the app - so it's not actually what's at risk here, despite the obvious
|
|
# first guess. See issue #339 / roadmap for the full trace.)
|
|
-keep class com.fr3ts0n.pvs.ProcessVar {
|
|
public <init>();
|
|
}
|
|
-keep class * extends com.fr3ts0n.pvs.ProcessVar {
|
|
public <init>();
|
|
}
|
|
|
|
# R8's default class repackaging moves classes into the root package, which
|
|
# breaks any *relative* Class.getResource()/getResourceAsStream() call -
|
|
# EcuDataItems.loadFromResource() does exactly this
|
|
# (getClass().getResource("prot/obd/res/pids.csv")), and the resource file
|
|
# itself is untouched (present in the APK either way) but the lookup path
|
|
# no longer matches once the class moves. Crashed on every launch of the
|
|
# first R8-shrunk build (NullPointerException in ObdProt's static
|
|
# initializer). Keeping package names avoids this whole bug class for any
|
|
# current or future relative-resource lookup, at negligible size cost.
|
|
-keeppackagenames
|