Adding ProGuard to Android toolchain

Do you have an up to date testcase for this?

tests.obfuscate.zip (3.5 MB)

1 Like

Thanks, logged as bugs://82963

1 Like

You want:
[assembly:Obfuscate(PublicMembers := true, PublicTypes := true)]

all members in this testcase are public and by default we only do private members. Above forces it.

1 Like

bugs://82963 got closed with status fixed.

Ah for some reason I thought it was the reverse. Thanks Carlo.

@ck does https://docs.elementscompiler.com/API/Aspects/Obfuscate/ reflect the correct defaults?

Yes it does.

1 Like

I get a crash due to ClassNotFoundException at startup when including [assembly:Obfuscate(PublicMembers := true, PublicTypes := true)]. It happened in my main project, and I created a new test project, with the only change being the added obfuscate aspect, and I got the same crash. Test project is below.

tests.obfuscate.zip (31.7 KB)

I can check in a bit; but you did ensure the MainActivity itself was not obfuscated right? Else android canā€™t find it (the manifest references it)

2 Likes

Nope I didnā€™t check that, I wouldnā€™t have expected that to be an issue. Can I not obfuscate any activities then? Android requires all activities to be listed in the manifestā€¦

1 Like

Indeed not.

Thatā€™s unfortunate :confused:

So then to use obfuscation in an Android project do I add the [assembly:Obfuscate] tag to my project and then [Obfuscate(PublicMembers := false, PublicTypes := false)] to every Activity/Service declaration?

Just [Obfuscate(PublicMembers := false)] will probably suffice, yes

Unfortunately that didnā€™t seem to fix it. In the test project uploaded here, I added [Obfuscate(Members := false, PublicMembers := false, PublicTypes := false)] to the line immediately preceding MainActivity = public class(Activity) but had the same ClassNotFound crash.

Usual caveats: are you sure the ClassNotFoundException is actually fatal? what class name does it mention?

Yep crashes at startup.

The activity marked in the manifest as the startup activity (in the case of the example project, MainActivity).

K. can you send me the complete latest test project; I wanna have a look at the dex log to see wats happening hereā€¦

1 Like

tests.obfuscate.zip (95.7 KB)

                     dex> processing a.class...
                     dex> processing b.class...
                     dex> processing b$c.class...
                     dex> processing b$d.class...
                     dex> processing b$e.class...
                     dex> processing b$f.class...

and no processing MainActivity. so yeah, itā€™s definitely still being obfuscatedā€¦ checking further, but might be a compiler-side issueā€¦

Update: this iOS working as it should, your attribute is wring, as you still have [Obfuscate] on the class, and just have its members excluded.

what you want is [Obfuscate(false)], and presto:

                     dex> processing a.class...
                     dex> processing a$b.class...
                     dex> processing a$c.class...
                     dex> processing a$d.class...
                     dex> processing a$e.class...
                     dex> processing tests/obfuscate/MainActivity.class...