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

Android locale changing is broken #19521

Open
vanniktech opened this issue Oct 24, 2021 · 26 comments
Open

Android locale changing is broken #19521

vanniktech opened this issue Oct 24, 2021 · 26 comments

Comments

@vanniktech
Copy link
Contributor

Using fastlane 2.197.0 and Screengrab 2.1.1 and when doing so on my device, I'm getting the following exception:

             LocaleUtil  E  Failed to change device locale to tools.fastlane.screengrab.locale.LocaleListCompat@94127e4
                         E  java.lang.ClassNotFoundException: $Proxy1
                         E      at java.lang.Class.classForName(Native Method)
                         E      at java.lang.Class.forName(Class.java:454)
                         E      at java.lang.Class.forName(Class.java:379)
                         E      at tools.fastlane.screengrab.locale.LocaleUtil.changeDeviceLocaleTo(LocaleUtil.java:39)
                         E      at tools.fastlane.screengrab.locale.LocaleTestRule$1.evaluate(LocaleTestRule.java:45)
                         E      at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
                         E      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:349)
                         E      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
                         E      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
                         E      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:314)
                         E      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                         E      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:312)
                         E      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                         E      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
                         E      at org.junit.runners.ParentRunner.run(ParentRunner.java:396)
                         E      at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:162)
                         E      at org.junit.runners.Suite.runChild(Suite.java:128)
                         E      at org.junit.runners.Suite.runChild(Suite.java:27)
                         E      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:314)
                         E      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                         E      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:312)
                         E      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                         E      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
                         E      at org.junit.runners.ParentRunner.run(ParentRunner.java:396)
                         E      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                         E      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
                         E      at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
                         E      at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:444)
                         E      at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)
                         E  Caused by: java.lang.ClassNotFoundException: Didn't find class "$Proxy1" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock
                            .jar", zip file "/data/app/com.vanniktech.boardmoney.test-gyKOXKh28FCUnNo7iRFN6A==/base.apk", zip file "/data/app/com.vanniktech.boardmoney-MYfhZojA65BjJ6VYcg1g-Q==/base.apk"],nativeLibraryDirec
                            tories=[/data/app/com.vanniktech.boardmoney.test-gyKOXKh28FCUnNo7iRFN6A==/lib/x86, /data/app/com.vanniktech.boardmoney-MYfhZojA65BjJ6VYcg1g-Q==/lib/x86, /system/lib, /system/product/lib]]
                         E      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
                         E      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                         E      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                         E      ... 29 more

I've been trying to isolate this into a reproduction project but wasn't successful to do so. Do you know what the reason behind this could be?

I'm running an 29 emulator with target/compileSdk set to 31 and building with Gradle 7.2 & AGP 7.0.3

@fastlane-bot
Copy link

It seems like you have not included the output of fastlane env
To make it easier for us help you resolve this issue, please update the issue to include the output of fastlane env 👍

@vanniktech
Copy link
Contributor Author

vanniktech commented Oct 24, 2021

✅ fastlane environment ✅

Stack

Key Value
OS 11.6
Ruby 2.6.3
Bundler? false
Git git version 2.33.0
Installation Source /usr/local/bin/fastlane
Host macOS 11.6 (20G165)
Ruby Lib Dir /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
OpenSSL Version LibreSSL 2.8.3
Is contained false
Is homebrew false
Is installed via Fabric.app false
Xcode Path /Applications/Xcode.app/Contents/Developer/
Xcode Version 13.0
Swift Version 5.5

System Locale

Variable Value
LANG en_US.UTF-8
LC_ALL en_US.UTF-8
LANGUAGE

fastlane files:

No Fastfile found

No Appfile found

fastlane gems

Gem Version Update-Status
fastlane 2.197.0 ✅ Up-To-Date

Loaded fastlane plugins:

No plugins Loaded

Loaded gems
Gem Version
did_you_mean 1.4.0
rouge 2.0.7
xcpretty 0.3.0
terminal-notifier 2.0.0
unicode-display_width 1.6.0
terminal-table 1.8.0
plist 3.5.0
public_suffix 4.0.6
addressable 2.8.0
multipart-post 2.0.0
word_wrap 1.0.0
optparse 0.1.1
tty-screen 0.7.0
tty-cursor 0.7.0
tty-spinner 0.9.1
artifactory 3.0.15
babosa 1.0.4
colored 1.2
highline 2.0.3
commander 4.6.0
excon 0.76.0
faraday-net_http 1.0.1
ruby2_keywords 0.0.4
faraday 1.3.0
unf_ext 0.0.7.6
unf 0.1.4
domain_name 0.5.20190701
http-cookie 1.0.3
faraday-cookie_jar 0.0.7
faraday_middleware 1.0.0
fastimage 2.2.0
gh_inspector 1.1.3
mini_magick 4.9.5
naturally 2.2.1
rubyzip 2.3.0
security 0.1.3
xcpretty-travis-formatter 1.0.0
dotenv 2.7.6
simctl 1.6.6
jwt 2.2.2
uber 0.1.0
declarative 0.0.20
declarative-option 0.1.0
representable 3.0.4
retriable 3.1.2
mini_mime 1.0.2
memoist 0.16.0
multi_json 1.14.1
os 1.0.1
signet 0.14.0
googleauth 0.16.2
httpclient 2.8.3
webrick 1.4.2
google-apis-core 0.4.0
google-apis-playcustomapp_v1 0.5.0
google-apis-androidpublisher_v3 0.8.0
google-cloud-env 1.3.3
google-cloud-errors 1.0.1
google-cloud-core 1.6.0
google-apis-iamcredentials_v1 0.6.0
google-apis-storage_v1 0.6.0
digest-crc 0.6.3
google-cloud-storage 1.34.1
emoji_regex 3.0.0
jmespath 1.4.0
aws-partitions 1.434.0
aws-eventstream 1.1.1
aws-sigv4 1.2.3
aws-sdk-core 3.113.0
aws-sdk-kms 1.43.0
aws-sdk-s3 1.92.0
rexml 3.2.5
nanaimo 0.3.0
colored2 3.1.2
claide 1.0.3
CFPropertyList 3.0.3
atomos 0.1.3
xcodeproj 1.21.0
json 2.3.1
bundler 2.1.4
rake 13.0.3
forwardable 1.3.1
logger 1.3.0
date 3.0.1
stringio 0.0.2
zlib 1.0.0
ipaddr 1.2.2
openssl 2.1.2
ostruct 0.1.0
strscan 1.0.0
io-console 0.5.6
fileutils 1.4.1
libxml-ruby 3.2.1
psych 3.1.0
mutex_m 0.1.0

generated on: 2021-10-24

@vanniktech
Copy link
Contributor Author

This seems to be the line that's causing the failure:

amnClass = Class.forName(activityManagerNative.getClass().getName());

@Kenneth9388
Copy link

Kenneth9388 commented Oct 28, 2021

Thanks for sharing. I found a lot of interesting information here. mcdvoice survey

@vanniktech
Copy link
Contributor Author

On Emulator running S (31) I'm getting:

             LocaleUtil  E  Failed to change device locale to tools.fastlane.screengrab.locale.LocaleListCompat@e4cc313
                         E  java.lang.ClassNotFoundException: $Proxy3
                         E      at java.lang.Class.classForName(Native Method)
                         E      at java.lang.Class.forName(Class.java:454)
                         E      at java.lang.Class.forName(Class.java:379)
                         E      at tools.fastlane.screengrab.locale.LocaleUtil.changeDeviceLocaleTo(LocaleUtil.java:39)
                         E      at tools.fastlane.screengrab.locale.LocaleTestRule$1.evaluate(LocaleTestRule.java:45)
                         E      at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
                         E      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:349)
                         E      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
                         E      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
                         E      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:314)
                         E      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                         E      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:312)
                         E      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                         E      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
                         E      at org.junit.runners.ParentRunner.run(ParentRunner.java:396)
                         E      at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:162)
                         E      at org.junit.runners.Suite.runChild(Suite.java:128)
                         E      at org.junit.runners.Suite.runChild(Suite.java:27)
                         E      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:314)
                         E      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                         E      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:312)
                         E      at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                         E      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
                         E      at org.junit.runners.ParentRunner.run(ParentRunner.java:396)
                         E      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                         E      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
                         E      at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
                         E      at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:444)
                         E      at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2248)
                         E  Caused by: java.lang.ClassNotFoundException: Didn't find class "$Proxy3" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock
                            .jar", zip file "/system/framework/android.test.base.jar", zip file "/data/app/~~3XX5KwAfT1ZUgGAjpoJ97w==/com.vanniktech.rssreader.test-Woi4ZMjvKTZ9YLaFOyQHWg==/base.apk", zip file "/data/app/~~
                            QbeFHp04g99dkQ85Osdxvw==/com.vanniktech.rssreader-Ep9x7yyKf5HCzstApMS7Pg==/base.apk"],nativeLibraryDirectories=[/data/app/~~3XX5KwAfT1ZUgGAjpoJ97w==/com.vanniktech.rssreader.test-Woi4ZMjvKTZ9YLa
                            FOyQHWg==/lib/x86_64, /data/app/~~QbeFHp04g99dkQ85Osdxvw==/com.vanniktech.rssreader-Ep9x7yyKf5HCzstApMS7Pg==/lib/x86_64, /system/lib64, /system_ext/lib64]]
                         E      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
                         E      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                         E      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                         E      ... 29 more

@sgrgrsn
Copy link

sgrgrsn commented Oct 28, 2021

This issue sounds like it's related to this issue.

@vanniktech
Copy link
Contributor Author

@sgrgrsn I'm not sure I understand. My problem is coming from the Android screengrab lib and not from fastlane itself (which is what your workaround is about)

@fastlane-bot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest fastlane version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Friendly reminder: contributions are always welcome! Check out CONTRIBUTING.md for more information on how to help with fastlane and feel free to tackle this issue yourself 💪

This issue will be auto-closed if there is no reply within 1 month.

@vanniktech
Copy link
Contributor Author

Yes still an issue.

@KaiEssmann
Copy link

Can confirm, this is still an issue.

@JulianEzequielPico-MM
Copy link

Same here, running on Android 12.

@pachlava
Copy link

Same. fastlane 2.199.0, screengrab 2.1.1 running against Pixel 2 XL API 28.

@joshdholtz
Copy link
Member

I guess I should probably fix it 🙃 I'll see if I can figure out what's going on and get a fix out this week

@fastlane-bot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest fastlane version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Friendly reminder: contributions are always welcome! Check out CONTRIBUTING.md for more information on how to help with fastlane and feel free to tackle this issue yourself 💪

This issue will be auto-closed if there is no reply within 1 month.

@JulianEzequielPico-MM
Copy link

Commenting just because this was not fixed :D

@vanniktech
Copy link
Contributor Author

@joshdholtz have you found out what's causing the locale changing to be broken? I've got nothing except my stack trace

@fastlane-bot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest fastlane version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Friendly reminder: contributions are always welcome! Check out CONTRIBUTING.md for more information on how to help with fastlane and feel free to tackle this issue yourself 💪

This issue will be auto-closed if there is no reply within 1 month.

@vanniktech
Copy link
Contributor Author

It's still broken.

@AaronMT
Copy link

AaronMT commented Jun 27, 2022

Slightly different stack, but same problem I think. Trying on an API 30 AVD, I get a RuntimeException with screengrab 2.206.2.

java.lang.RuntimeException: java.lang.ClassNotFoundException: $Proxy9
[14:28:08]: ▸ 	at tools.fastlane.screengrab.locale.LocaleUtil.changeDeviceLocaleTo(LocaleUtil.java:52)
[14:28:08]: ▸ 	at tools.fastlane.screengrab.locale.LocaleTestRule$1.evaluate(LocaleTestRule.java:30)
[14:28:08]: ▸ 	at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:134)
[14:28:08]: ▸ 	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
[14:28:08]: ▸ 	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
[14:28:08]: ▸ 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
[14:28:08]: ▸ 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
[14:28:08]: ▸ 	at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:162)
[14:28:08]: ▸ 	at org.junit.runners.Suite.runChild(Suite.java:128)
[14:28:08]: ▸ 	at org.junit.runners.Suite.runChild(Suite.java:27)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
[14:28:08]: ▸ 	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
[14:28:08]: ▸ 	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
[14:28:08]: ▸ 	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
[14:28:08]: ▸ 	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
[14:28:08]: ▸ 	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:444)
[14:28:08]: ▸ 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)

@hichamboushaba
Copy link

We have the same issue, and after investigating, we found out that this is not a bug of screengrab, but instead it was a conflict with LeakCanary.
LeakCanary replaces the default IActivityManager with with a proxy instance here, which causes the ClassNotFoundException when screengrab tries to access it using reflection.

So check if you are using LeakCanary or check for other libraries that may be doing the same thing.

For LeakCanary, the fix is to avoid installing it on test builds, for now, we are doing it by using leakcanary-android-core artifact, and handling the initialization manually on non-test builds, but I believe there are other ways to handle this by using a specific testBuildType.

@fastlane-bot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest fastlane version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Friendly reminder: contributions are always welcome! Check out CONTRIBUTING.md for more information on how to help with fastlane and feel free to tackle this issue yourself 💪

This issue will be auto-closed if there is no reply within 1 month.

@vanniktech
Copy link
Contributor Author

Still somewhat of an issue.

@sergio-sastre
Copy link

@vanniktech
The problem is that LocaleTestRule is using Configuration#updateConfiguration() in LocaleUtil method, that since API 28 belongs to the non-sdk interfaces.

There are 2 ways to overcome the problem.

  1. via adb
    One should execute the following commands before executing the screengrab script, depending on the API level:

For Android 9 (API level 28)

adb shell settings put global hidden_api_policy_pre_p_apps 1
adb shell settings put global hidden_api_policy_p_apps 1

For Android 10 (API level 29) or higher

adb shell settings put global hidden_api_policy 1
  1. In Java code, by using libraries like AndroidHiddenApiBypass
    You can find a fixed version of fastlane's LocaleUtil.java here

The interesting part is this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
   HiddenApiBypass.invoke(
      amnClass,
      activityManagerNative,
      "updateConfiguration",
      config
    );
} else {
      Method updateConfigurationMethod =
           amnClass.getMethod("updateConfiguration", Configuration.class);
      updateConfigurationMethod.setAccessible(true);
      updateConfigurationMethod.invoke(activityManagerNative, config);
}

@fastlane-bot
If you prefer to go for the second solution, which is more practical as a fastlane user, I'd be glad to create a PR

@fastlane-bot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest fastlane version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

Friendly reminder: contributions are always welcome! Check out CONTRIBUTING.md for more information on how to help with fastlane and feel free to tackle this issue yourself 💪

This issue will be auto-closed if there is no reply within 1 month.

@vanniktech
Copy link
Contributor Author

Still an issue

@maxdelia
Copy link

Still an issue 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests