0

Context :

Xamarin.Android in VS2019 - Target : Android 9.0 (API 28) - App using AndroidX.AppCompat.App - App deployed to a Samsung SM-G935F (Android 8.0 - API 26). Linking is set to SDK Assemblies only. DEX compiler is set to dx.

Dotfuscator Community (VS 2019) 5.44.0 integrated using the [official guide] (https://www.preemptive.com/dotfuscator/ce/docs/help/getting_started_xamarin.html).

So at the end of .csproj file is added the following :

<PropertyGroup>
    <DotfuscatorXamarinConfigFileName>DotfuscatorConfig.xml</DotfuscatorXamarinConfigFileName>
    <DotfuscatorXamarinCliPath>E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE\dotfuscatorCLI.exe</DotfuscatorXamarinCliPath>
    <DotfuscatorXamarinGenerateNewConfigFile>true</DotfuscatorXamarinGenerateNewConfigFile>
    <!-- Enable Dotfuscator for Release -->
    <DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'Release'">true</DotfuscatorXamarinEnabled>
    <!-- Enable Dotfuscator for Ad-Hoc (only needed for iOS) -->
    <DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'Ad-Hoc'">true</DotfuscatorXamarinEnabled>
    <!-- Enable Dotfuscator for AppStore (only needed for iOS) -->
    <DotfuscatorXamarinEnabled Condition="'$(Configuration)' == 'AppStore'">true</DotfuscatorXamarinEnabled>
  </PropertyGroup>
  <Import Project=PATH TO PreEmptive.Dotfuscator.Xamarin.Targets/>

Problem :

App launches fine in release build with either code shrinker r8 or dotfuscator but not with both ("App has stopped" at launch). Is it a known issue ?

Each time I change project configuration (r8 alone, dotfuscator alone or both), I do a clean, delete obj and bin folder and rebuild. (Each time, I have to relaunch VS2019 3 times before Samsung device finally appears, it was not complicated enough).

Output Window only shows the following :

Start debugging Android application ...
Android application is running (debug is disabled in android project properties).

I can't figure out how to enable debug for release mode (ticking "Enable developper instrumentation" does not change anything) to get more information.

An error appear in the logcat when the app crashes (so only with both r8 and dotfuscator) :

java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.FitWindowsLinearLayout" ...

Xamarin log is as follow :

Xamarin.VisualStudio.TastyPackage|Information|0|Hooked up SDB tracing adapter
Xamarin.VisualStudio.TastyPackage|Information|0|Initialization finished
Xamarin|Information|0|Xamarin - 16.6.000.1064-d16-6+b03f31e
Xamarin.VisualStudio.TastyPackage|Information|0|Hooked up SDB tracing adapter
Xamarin.VisualStudio.TastyPackage|Information|0|Initialization finished
Xamarin.VisualStudio.Android.XamarinAndroidPackage|Warning|0|Initializing Xamarin.VisualStudio.Android.XamarinAndroidPackage
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing AndroidStarted event
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify mustCheckIfSolutionIsReady:True delay:00:00:02
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify canceled => solution is not ready
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ActiveProjectConfigurationChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify mustCheckIfSolutionIsReady:True delay:00:00:02
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify canceled => solution is not ready
Xamarin.HotReload|Information|0|2020-07-23 03:54:54.1 Hot Reload IDE Extension Loaded
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.ProjectSystem.PackageServices|Warning|0|Failed to Restore Nuget packages for project (CSPROJ PATH).
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error: 
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ManifestChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error: 
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ManifestChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ManifestChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error: 
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error: 
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ManifestChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error: 
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: processing ManifestChanged event
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: verify android sdk installed
Xamarin.VisualStudio.Android.Setup.AndroidSdkValidation|Information|0|androidsdksetup: removing android sdk errors
Xamarin.VisualStudio.Android.Setup.AndroidSdkSetup|Information|0|androidsdksetup: verify error:
Elaws
  • 1
  • 5
  • Hi, I work for the Dotfuscator team. I haven't been able to reproduce the issue - could you edit your question to include what Dotfuscator version and edition (Professional or Community/CE) you are using? Also, have you checked the Android Device Log (logcat)? – Joe Sewell Jul 23 '20 at 14:53
  • Hi @JoeSewell and thanks for your reply. I added details to original post. I use Dotfuscator Community `5.44.0` (VS 2019). Thanks for logcat suggestion : indeed an error appears (only when using both r8 and dotfuscator) : `java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.widget.FitWindowsLinearLayout"` – Elaws Jul 23 '20 at 18:32
  • @JoeSewell : So after adding `-keep public class AndroidX.AppCompat.Widget.** { *; }` to proguard.cfg (without forgetting to set its build action to `ProguardConfiguration`), the app does not crash anymore. Not sure why though, because it worked fine with r8 alone (or dotfuscator alone) and without this config file. I looked at the generated `dll` file and most of the code is readable : about 80% of functions and nearly all variables have not been renamed. So I'm not sure if I missed some VS2019 or dotfuscator configuration for better efficiency (linking configuration?) ? – Elaws Jul 23 '20 at 21:06
  • I'm glad you were able to resolve your original issue. Regarding the number of types / members that are renamed, have you disabled [library mode](https://www.preemptive.com/dotfuscator/ce/docs/help/obfuscation_overview.html#library-mode)? That mode keeps all the public names, in case external code, XAML, or reflection is using those names. Note that if you do disable this mode, you may need to add some [manual exclusions](https://www.preemptive.com/dotfuscator/ce/docs/help/gui_renaming.html#pctoc-exclusions-tab) to account for those scenarios. – Joe Sewell Jul 24 '20 at 13:55
  • Hi, I work on the R8 team, and @JoeSewell I wonder, if dotfuscator will do any rewriting into reflective code, so that R8 cannot trace the code without additional `-keep` rules? – sgjesse Jul 27 '20 at 09:02
  • @sgjesse I know that Xamarin generates some amount of Java code based off the project's .NET code. Dotfuscator modifies the compiled .NET code before this Java code is generated, but I don't know the specifics of this case. I'm going to try reproducing the issue again, now that I know `FitWindowsLinearLayout` is the affected type, but maybe you could clarify your question? – Joe Sewell Jul 27 '20 at 14:11
  • @JoeSewell When an app processed by R8 reports a missing class then it is typically caused by the R8 tracing algorithm not being able to statically determine that that particulair class is ever used (instantiated). This is usually caused by reflective code and in these cases `-keep` rules are required. There is a short Medium post - https://medium.com/androiddevelopers/shrinking-your-app-with-r8-909efac25de4 - with the basics. Also see https://developer.android.com/studio/build/shrink-code. This could also be a bug in R8 - not sure which version i used by `VS2019`. – sgjesse Jul 29 '20 at 07:17

0 Answers0