From d0ff30df9f52516924161bd304f4a474ad22407d Mon Sep 17 00:00:00 2001 From: Syer10 Date: Wed, 24 Mar 2021 20:28:34 -0400 Subject: [PATCH 1/2] Create getAndroid.ps1 --- AndroidCompat/getAndroid.ps1 | 90 ++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 AndroidCompat/getAndroid.ps1 diff --git a/AndroidCompat/getAndroid.ps1 b/AndroidCompat/getAndroid.ps1 new file mode 100644 index 00000000..b778dca5 --- /dev/null +++ b/AndroidCompat/getAndroid.ps1 @@ -0,0 +1,90 @@ +if ($(Split-Path -Path (Get-Location) -Leaf) -eq "AndroidCompat" ) { + Set-Location .. +} + +Write-Output "Getting required Android.jar..." +Remove-Item -Recurse -Force "tmp" | Out-Null +New-Item -ItemType Directory -Force -Path "tmp" | Out-Null + +$androidEncoded = (Invoke-WebRequest -Uri "https://android.googlesource.com/platform/prebuilts/sdk/+/3b8a524d25fa6c3d795afb1eece3f24870c60988/27/public/android.jar?format=TEXT").content + +$android_jar = (Get-Location).Path + "\tmp\android.jar" + +[IO.File]::WriteAllBytes($android_jar, [Convert]::FromBase64String($androidEncoded)) + +# We need to remove any stub classes that we might use +Write-Output "Patching JAR..." + +function Remove-Files-Zip($zipfile, $path) +{ + [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression') | Out-Null + + $stream = New-Object IO.FileStream($zipfile, [IO.FileMode]::Open) + $mode = [IO.Compression.ZipArchiveMode]::Update + $zip = New-Object IO.Compression.ZipArchive($stream, $mode) + + ($zip.Entries | Where-Object { $_.FullName -like $path }) | ForEach-Object { Write-Output "Deleting: $($_.FullName)"; $_.Delete() } + + $zip.Dispose() + $stream.Close() + $stream.Dispose() +} + +Write-Output "Removing org.json..." +Remove-Files-Zip $android_jar 'org/json/*' + +Write-Output "Removing org.apache..." +Remove-Files-Zip $android_jar 'org/apache/*' + +Write-Output "Removing org.w3c..." +Remove-Files-Zip $android_jar 'org/w3c/*' + +Write-Output "Removing org.xml..." +Remove-Files-Zip $android_jar 'org/xml/*' + +Write-Output "Removing org.xmlpull..." +Remove-Files-Zip $android_jar 'org/xmlpull/*' + +Write-Output "Removing junit..." +Remove-Files-Zip $android_jar 'junit/*' + +Write-Output "Removing javax..." +Remove-Files-Zip $android_jar 'javax/*' + +Write-Output "Removing java..." +Remove-Files-Zip $android_jar 'java/*' + +Write-Output "Removing overriden classes..." +Remove-Files-Zip $android_jar 'android/app/Application.class' +Remove-Files-Zip $android_jar 'android/app/Service.class' +Remove-Files-Zip $android_jar 'android/net/Uri.class' +Remove-Files-Zip $android_jar 'android/net/Uri$Builder.class' +Remove-Files-Zip $android_jar 'android/os/Environment.class' +Remove-Files-Zip $android_jar 'android/text/format/Formatter.class' +Remove-Files-Zip $android_jar 'android/text/Html.class' + +function Dedupe($path) +{ + Push-Location $path + $classes = Get-ChildItem . *.* -Recurse | Where-Object { !$_.PSIsContainer } + $classes | ForEach-Object { + "Processing class: $($_.FullName)" + Remove-Files-Zip $android_jar "$($_.Name).class" | Out-Null + Remove-Files-Zip $android_jar "$($_.Name)$*.class" | Out-Null + Remove-Files-Zip $android_jar "$($_.Name)Kt.class" | Out-Null + Remove-Files-Zip $android_jar "$($_.Name)Kt$*.class" | Out-Null + } + Pop-Location +} + +Dedupe "AndroidCompat/src/main/java" +Dedupe "server/src/main/java" +Dedupe "server/src/main/kotlin" + +Write-Output "Copying Android.jar to library folder..." +Move-Item -Force $android_jar "AndroidCompat/lib/android.jar" + +Write-Output "Cleaning up..." +Remove-Item -Recurse -Force "tmp" + +Write-Output "Done!" \ No newline at end of file From f6ce010aa2c57ce932a8256d2c50fd17492cf8a7 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Wed, 24 Mar 2021 20:34:32 -0400 Subject: [PATCH 2/2] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f5de33b6..0464ec1f 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ This project has two components: #### Manual download Download [android.jar](https://raw.githubusercontent.com/Suwayomi/Tachidesk/android-jar/android.jar) and put it under `AndroidCompat/lib`. #### Automated download(needs `bash`, `curl`, `base64`, `zip` to work) -Run `AndroidCompat/getAndroid.sh` from project's root directory to download and rebuild the jar file from Google's repository. +Run `AndroidCompat/getAndroid.sh`(MacOS/Linux) or `AndroidCompat/getAndroid.ps1`(Windows) from project's root directory to download and rebuild the jar file from Google's repository. ### Prerequisite: Software dependencies You need this software packages installed in order to build this project: - Java Development Kit and Java Runtime Environment version 8 or newer(both Oracle JDK and OpenJDK works)