# Template file for 'android-studio'
pkgname=android-studio
version=2024.2.1.9
revision=1
archs="x86_64"
hostmakedepends="tar"
short_desc="Official Android IDE"
maintainer="Bnyro <bnyro@tutanota.com>"
license="Apache-2.0"
homepage="https://developer.android.com/studio/"
changelog="https://developer.android.com/studio/releases/"
distfiles="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-${version}-linux.tar.gz"
checksum=d7ca6955e02fc71ea43413a348a7198db10c36df2484a9a884cab7244ad7ee96
repository=nonfree
restricted=yes
python_version=3
nostrip=yes
noshlibprovides=yes

# These files are not run or loaded on the host thus skip scanning their runtime deps
skiprdeps="/opt/android-studio/plugins/android/resources/process-tracker-agent/native/x86_64/process-tracker
 /opt/android-studio/plugins/android/resources/process-tracker-agent/native/armeabi-v7a/process-tracker
 /opt/android-studio/plugins/android/resources/process-tracker-agent/native/arm64-v8a/process-tracker
 /opt/android-studio/plugins/android/resources/process-tracker-agent/native/x86/process-tracker
 /opt/android-studio/plugins/android/resources/screen-sharing-agent/x86_64/libscreen-sharing-agent.so
 /opt/android-studio/plugins/android/resources/screen-sharing-agent/armeabi-v7a/libscreen-sharing-agent.so
 /opt/android-studio/plugins/android/resources/screen-sharing-agent/arm64-v8a/libscreen-sharing-agent.so
 /opt/android-studio/plugins/android/resources/screen-sharing-agent/x86/libscreen-sharing-agent.so
 /opt/android-studio/plugins/android/resources/installer/x86_64/installer
 /opt/android-studio/plugins/android/resources/installer/armeabi-v7a/installer
 /opt/android-studio/plugins/android/resources/installer/arm64-v8a/installer
 /opt/android-studio/plugins/android/resources/installer/x86/installer
 /opt/android-studio/plugins/android/resources/transport/x86_64/transport
 /opt/android-studio/plugins/android/resources/transport/native/agent/x86_64/libjvmtiagent.so
 /opt/android-studio/plugins/android/resources/transport/native/agent/armeabi-v7a/libjvmtiagent.so
 /opt/android-studio/plugins/android/resources/transport/native/agent/arm64-v8a/libjvmtiagent.so
 /opt/android-studio/plugins/android/resources/transport/native/agent/x86/libjvmtiagent.so
 /opt/android-studio/plugins/android/resources/transport/armeabi-v7a/transport
 /opt/android-studio/plugins/android/resources/transport/arm64-v8a/transport
 /opt/android-studio/plugins/android/resources/transport/x86/transport
 /opt/android-studio/plugins/android/resources/perfetto/x86_64/libperfetto.so
 /opt/android-studio/plugins/android/resources/perfetto/x86_64/traced_probes
 /opt/android-studio/plugins/android/resources/perfetto/x86_64/traced
 /opt/android-studio/plugins/android/resources/perfetto/x86_64/perfetto
 /opt/android-studio/plugins/android/resources/perfetto/armeabi-v7a/libperfetto.so
 /opt/android-studio/plugins/android/resources/perfetto/armeabi-v7a/traced_probes
 /opt/android-studio/plugins/android/resources/perfetto/armeabi-v7a/traced
 /opt/android-studio/plugins/android/resources/perfetto/armeabi-v7a/perfetto
 /opt/android-studio/plugins/android/resources/perfetto/arm64-v8a/libperfetto.so
 /opt/android-studio/plugins/android/resources/perfetto/arm64-v8a/traced_probes
 /opt/android-studio/plugins/android/resources/perfetto/arm64-v8a/traced
 /opt/android-studio/plugins/android/resources/perfetto/arm64-v8a/perfetto
 /opt/android-studio/plugins/android/resources/perfetto/x86/libperfetto.so
 /opt/android-studio/plugins/android/resources/perfetto/x86/traced_probes
 /opt/android-studio/plugins/android/resources/perfetto/x86/traced
 /opt/android-studio/plugins/android/resources/perfetto/x86/perfetto
 /opt/android-studio/plugins/android-ndk/resources/lldb/lib/python3.10/lib-dynload/_curses.cpython-310-x86_64-linux-gnu.so
 /opt/android-studio/plugins/android-ndk/resources/lldb/lib/python3.10/lib-dynload/_curses_panel.cpython-310-x86_64-linux-gnu.so"

post_extract() {
	bsdtar xf lib/app.jar entry.desktop
}

post_patch() {
	vsed -i -e 's/\$NAME\$/Android Studio/' entry.desktop
	vsed -i -e 's/\$ICON\$/\/opt\/android-studio\/bin\/studio.svg/' entry.desktop
	vsed -i -e 's/\$SCRIPT\$/android-studio/' entry.desktop
	vsed -i -e 's/\$COMMENT\$/The Drive to Develop/' entry.desktop
	vsed -i -e 's/\$WM_CLASS\$/jetbrains-studio/' entry.desktop
}

do_install() {
	vmkdir opt/${pkgname}
	vcopy bin opt/${pkgname}/
	vcopy lib opt/${pkgname}/
	vcopy jbr opt/${pkgname}/
	vcopy plugins opt/${pkgname}/
	vcopy build.txt opt/${pkgname}/ # read as IDE version information
	vcopy product-info.json opt/${pkgname}/
	vmkdir usr/bin
	ln -s /opt/android-studio/bin/studio.sh ${DESTDIR}/usr/bin/android-studio

	vinstall entry.desktop 644 usr/share/applications android-studio.desktop
	chmod -R ugo+rX ${DESTDIR}/opt
}
