Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration options cannot be parsed on Android in release builds #294

Closed
wwwdata opened this issue Feb 24, 2020 · 4 comments
Closed

Configuration options cannot be parsed on Android in release builds #294

wwwdata opened this issue Feb 24, 2020 · 4 comments

Comments

@wwwdata
Copy link
Contributor

wwwdata commented Feb 24, 2020

After a quick debugging session for issue #237 I found out why it is not working. When Android is compiled for production, the code is optimized and named fields are renamed to a shorter variable name and mapped.

Unfortunately, the code for the configuration uses reflections to directly map values to field names. This cannot work in production when the optimizations are run because all the fields will have different names. It all works when you disable this feature, but this is not the solution. The solution would be to manually map everything without reflection features.

So release woks when minify and shrink is disabled in the release config

buildTypes {  
  release {       
    minifyEnabled false        
    shrinkResources false      
  }    
}

So, this code will fail for release when the variable names are optimized

try {
this.getClass().getDeclaredField(pair.getKey()).set(this, value);
} catch (NoSuchFieldException e) {
Log.d(LOG_TAG, e.getMessage());
} catch (IllegalAccessException e) {
Log.d(LOG_TAG, e.getMessage());
}
}

I noticed that in release builds, lots of those errors were popping up. Example of an error message:

02-24 11:10:14.942 15395 15395 D InAppWebViewOptions: No field useShouldOverrideUrlLoading in class Lcom/pichillilorenzo/flutter_inappwebview/InAppWebView/H; (declaration of 'com.pichillilorenzo.flutter_inappwebview.InAppWebView.H' appears in base.apk)
02-24 11:10:14.942 15395 15395 D InAppWebViewOptions: No field preferredContentMode in class Lcom/pichillilorenzo/flutter_inappwebview/InAppWebView/H; (declaration of 'com.pichillilorenzo.flutter_inappwebview.InAppWebView.H' appears in ba

Essentially this means that on Android, it was always using the configuration defaults and it was not possible to override any configuration at all.

@pichillilorenzo are you already working on this for the big refactoring you are doing at the moment? Or are you aware of this issue? We basically just have to get rid of the reflection usage and then I guess a lot of Android bug reports can be closed. I guess the shouldOverrideUrlLoading is not the only issue related to this problem.

@wwwdata
Copy link
Contributor Author

wwwdata commented Feb 24, 2020

This is also related #280
Sorry for not commenting there, but I guess here, we have the full explanation of why it is happening and can close the other issue.

@aboutmydreams
Copy link

thanks very much

@pichillilorenzo
Copy link
Owner

Released new version 3.0.0!

This was referenced Jul 6, 2020
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants