ReVanced / revanced-patches

🧩 Patches for ReVanced
https://revanced.app
GNU General Public License v3.0
2.36k stars 271 forks source link

bug: TikTok: Failed to apply patches: Dependency errors with 'Settings' causing multiple failures #525

Closed 54m4d closed 1 year ago

54m4d commented 1 year ago

Type

Error while patching

Bug description

Getting this error while patching TikTok 30.7.2

Steps to reproduce

Just try to patch TikTok as any other app.

Relevant log output

Initializing installer
Creating working directory
Copying original apk
Unpacking input apk
Reading dex files
Decoding AndroidManifest.xml only, because resources are not needed
Merging integrations
An error occurred! Aborted
Error:
java.lang.OutOfMemoryError: Failed to allocate a 32 byte allocation with 4005744 free bytes and 3911KB until OOM, target footprint 536870912, growth limit 536870912; giving up on allocation because <1% of heap free after GC.
    at java.util.LinkedHashMap.newNode(LinkedHashMap.java:280)
    at java.util.HashMap.putVal(HashMap.java:641)
    at java.util.HashMap.put(HashMap.java:611)
    at brut.androlib.res.data.ResType.addResource(ResType.java:49)
    at brut.androlib.res.data.ResType.addResource(ResType.java:44)
    at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:363)
    at brut.androlib.res.decoder.ARSCDecoder.readTableType(ARSCDecoder.java:308)
    at brut.androlib.res.decoder.ARSCDecoder.readTableTypeSpec(ARSCDecoder.java:223)
    at brut.androlib.res.decoder.ARSCDecoder.readTablePackage(ARSCDecoder.java:132)
    at brut.androlib.res.decoder.ARSCDecoder.readTableHeader(ARSCDecoder.java:84)
    at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:50)
    at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:778)
    at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:66)
    at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:58)
    at brut.androlib.Androlib.getResTable(Androlib.java:74)
    at app.revanced.patcher.Patcher.decodeResources(Patcher.kt:204)
    at app.revanced.patcher.Patcher.access$decodeResources(Patcher.kt:38)
    at app.revanced.patcher.Patcher$executePatches$1.invokeSuspend(Patcher.kt:351)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlin.sequences.SequenceBuilderIterator.hasNext(SequenceBuilder.kt:129)
    at app.revanced.manager.flutter.MainActivity.runPatcher$lambda-32(MainActivity.kt:395)
    at app.revanced.manager.flutter.MainActivity.$r8$lambda$efRWk2Z7aIFbIqnpE9hv8LpAiuk(Unknown Source:0)
    at app.revanced.manager.flutter.MainActivity$$ExternalSyntheticLambda13.run(Unknown Source:24)
    at java.lang.Thread.run(Thread.java:1012)

Screenshots or videos

N/A

Solution

N/A

Additional context

No special context.

Invalidly closing the issue is not acceptable.

Acknowledgements

BrianPurgert commented 1 year ago

I get the same error I've tried a couple different versions of TikTok

LisoUseInAIKyrios commented 1 year ago

Are you patching with Manager, or with command line tools?

Edit: the stack trace shows it's Flutter, so it's patched with Manager.

54m4d commented 1 year ago

Manager v1.6.1

I've never succeeded in patching TikTok before, even with older Manager/TikTok versions, but today i decided to open the issue.

LisoUseInAIKyrios commented 1 year ago

File a bug report in Manager repository, it might be an issue with Manager not allocating enough memory to the patcher. Or there's a chance it's something going haywire during the patcher decoding and it's blowing out the device memory limit.

For now you can patch using command line tools, but you'll probably also have to include the -Xmx flag with a max memory value (ie: -Xmx2048M)

54m4d commented 1 year ago

I saw this comment there, so prolly not a Manager issue if that person is right.

io43 commented 1 year ago

yea it don't work with manager android13- pixel5 6gb ram , have to use the cli with revanced-patches jar and revanced-integrations apk instead, make sure to use an other java version (i'm using openjdk-18) if you see the error

org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$BCKeyStoreException: java.io.IOException: Error initialising store of key store: java.lang.SecurityException: JCE cannot authenticate the provider BC

while signing the apk with the cli

karx1 commented 1 year ago

Hi, I solved it by using the CLI, you can read this Reddit thread for a guide

54m4d commented 1 year ago

I'm a Manager user.

LisoUseInAIKyrios commented 1 year ago

This issue should be moved to Manager repository. This issue only shows up when patching with Manager.

Manager already has android:largeHeap="true" set.

But perhaps the Flutter/Dart settings can be adjusted? I've never used Flutter or Dart so I can't comment on this much. Maybe this is the fix?

Axelen123 commented 1 year ago

This issue should be moved to Manager repository. This issue only shows up when patching with Manager.

Manager already has android:largeHeap="true" set.

But perhaps the Flutter/Dart settings can be adjusted? I've never used Flutter or Dart so I can't comment on this much. Maybe this is the fix?

I don't think anything can be done. The problem is caused by the Android runtime not giving us enough java heap memory. Dart memory allocations don't contribute to that limit if I understand things correctly. People who run into this have to use the CLI in Termux instead, which does not have this memory limit.

LisoUseInAIKyrios commented 1 year ago

The OOM stack trace here shows the max heap is set to a modest 512MB (some users have shown OOM at 256MB), which seems small if the maxheap flag is being applied to the patching process.

If Dart does not contribute to the heap memory of the android app, then it must be running on its own process/service or some other memory isolation. That means it might be possible to increase the max memory of that process/service.

If this truly cannot be fixed, then maybe the OOM can be caught and the user informed that Manager won't work and CLI is required.

54m4d commented 1 year ago
  1. You guys need to agree if this is a Manager issue or not, as you may have seen, oSumAtrIX mentioned that it's not related to the Manager, but at least they gave a comment before closing that issue.

  2. If CLI is the only way to patch this, TikTok patches may be temporarily or permanently disabled in the Manager, with users being informed to use the CLI instead, in order to avoid confusion.

oSumAtrIX commented 1 year ago

There is no such thing as "Disabling" patches. TikTok can be patched on ReVanced Manager if you have enough memory, but the issue is inherently large memory usage due to dexlib2. ReVanced Manager can fix it by increasing max memory usage.

54m4d commented 1 year ago

Fixed in Manager v1.7.0

LisoUseInAIKyrios commented 1 year ago

Not sure how it was fixed when 1.7.0 has no patcher or memory related changes, but oh well 🤷🏼‍♂️

Axelen123 commented 1 year ago

There is no such thing as "Disabling" patches. TikTok can be patched on ReVanced Manager if you have enough memory, but the issue is inherently large memory usage due to dexlib2. ReVanced Manager can fix it by increasing max memory usage.

We already did and its still not enough for some devices

54m4d commented 1 year ago

I have tried the exact same process i tried with the previous Manager and i got no issues now, i have also tested with the version of TikTok where this issue appeared and i got no memory errors, It's fair to say Manager v1.7.0 fixed the memory issue.

LisoUseInAIKyrios commented 1 year ago

When patching using Termux, it doesn't have these memory limitations. And it's a regular android app, and it even has the memory overhead of running a full Linux system (which surely uses more memory than the ReVanced Manager UI).

Yet Termux has no OOM problems. For reference, Java command line in Termux shows a max heap memory of 1.8GB. Meanwhile the patcher in Flutter Manager is blowing out at 256 or 512MB.

Axelen123 commented 1 year ago

Termux does not run an entire operating system. It just launches linux processes. Only dalvik code running in ART is subjected to the problematic java heap limit. It does not apply when running the JRE in Termux.

54m4d commented 1 year ago

I believe i spoke a bit too soon. When i tried an older version of TikTok, i encountered a different error unrelated to memory issues.

The suggested version of Tiktok for patching should not be set as "All," as some versions work just fine, like 30.7.4 while others can throw errors like the one below, re-opening this issue since ReVanced Patches do not work properly with TikTok.

Initializing installer
Creating working directory
Copying original apk
Unpacking input apk
Reading dex files
Decoding AndroidManifest.xml only, because resources are not needed
Merging integrations
Executing patches
Failed to apply Downloads: 'Downloads' depends on 'Settings' but the following error was raised: Failed to resolve SettingsEntryFingerprint
Failed to apply Feed filter: 'Feed filter' depends on 'Settings' but the following error was raised: 'Settings' did not succeed previously
Applied Hide ads
Failed to apply Playback speed: NullPointerException
Failed to apply Settings: 'Settings' did not succeed previously
Failed to apply Sim spoof: 'Sim spoof' depends on 'Settings' but the following error was raised: 'Settings' did not succeed previously
Repacking patched apk
Not compiling resources because resource patching is not required
Writing modified dex files
Finished!
oSumAtrIX commented 1 year ago

This is not a patch issue. There is simply not enough RAM provided to patch the app on your end.

54m4d commented 1 year ago

So enough RAM is only provided to certain TikTok apks but not others, is that what you are trying to say?

In the last error, how can you tell if enough RAM was not provided?

oSumAtrIX commented 1 year ago

Enough RAM is needed to patch TikTok. The last error is a product of patching an old version.

54m4d commented 1 year ago

Forget the memory issue now, it has been addressed in Manager v1.7.0. and i tested and got no memory errors.

The last issue is not related to memory and the suggested version of Tiktok for patching is set to"All," so i don't understand why you mention "old version"? read my posts once again, you seem like you have a hard time distinguishing between a memory issue and something else, please re-open this issue.

@Axelen123 Can you confirm if this is a Manager issue or not?

Axelen123 commented 1 year ago

Can you confirm if this is a Manager issue or not?

Long answer: The memory issue is caused by the android app runtime (ART) not giving the patcher enough java heap memory. The only way to affect how much memory you are provided is to set the android:largeHeap attribute in the manifest, but we have already done that. The CLI is unaffected because it does not run in ART unlike manager.

Short answer: I would say this is a manager issue, but we cannot do anything about it.

If you are having another problem then you need to open a new issue so it can be tracked properly.