Skip to content

Commit cec4ddb

Browse files
committed
Depend directly on NewPipeExtractor's git repository
This should solve the Jitpack problems, where sometimes built artifacts disappear. This is not also done for nanojson and FilePicker because: - nanojson is not a gradle project, and thus cannot be built by gradle - FilePicker is using a very old version of gradle, and while that's not a problem when the project is built on its own, when importing is as a subproject it gets built with the same gradle version as NewPipe, which causes gradle issues However, for some reason we've been using the same Jitpack artifacts for the FilePicker and for nanojson since ages without issues, it's just NewPipeExtractor artifacts that sometimes disappear.
1 parent 18f1cf2 commit cec4ddb

4 files changed

Lines changed: 117 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ captures/
1111
*.class
1212
app/debug/
1313
app/release/
14+
checkouts/
1415

1516
# vscode / eclipse files
1617
*.classpath

app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ dependencies {
206206
coreLibraryDesugaring(libs.android.desugar)
207207

208208
/** NewPipe libraries **/
209-
implementation(libs.newpipe.nanojson)
210-
implementation(libs.newpipe.extractor)
211-
implementation(libs.newpipe.filepicker)
209+
implementation(libs.teamnewpipe.nanojson)
210+
implementation(libs.teamnewpipe.extractor)
211+
implementation(libs.teamnewpipe.filepicker)
212212

213213
/** Checkstyle **/
214214
checkstyle(libs.puppycrawl.checkstyle)

gradle/libs.versions.toml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ documentfile = "1.1.0"
1919
exoplayer = "2.19.1"
2020
fragment = "1.8.9"
2121
groupie = "2.10.1"
22+
# referenced in settings.gradle.kts
23+
includegitPlugin = "0.3.1"
2224
jsoup = "1.21.2"
2325
junit = "4.13.2"
2426
junit-ext = "1.3.0"
@@ -48,17 +50,18 @@ sonarqube = "7.0.1.6134"
4850
statesaver = "1.4.1" # TODO: Drop because it is deprecated and incompatible with KSP2
4951
stetho = "1.6.0"
5052
swiperefreshlayout = "1.1.0"
51-
# You can use a local version by uncommenting a few lines in settings.gradle
52-
# Or you can use a commit you pushed to GitHub by just replacing TeamNewPipe with your GitHub
53-
# name and the commit hash with the commit hash of the (pushed) commit you want to test
5453
# This works thanks to JitPack: https://jitpack.io/
5554
teamnewpipe-filepicker = "5.0.0"
5655
teamnewpipe-nanojson = "e9d656ddb49a412a5a0a5d5ef20ca7ef09549996"
57-
# WORKAROUND: if you get errors with the NewPipeExtractor dependency, replace `v0.XX.Y` with
58-
# the corresponding commit hash, since JitPack sometimes deletes artifacts.
59-
# If there’s already a git hash, just add more of it to the end (or remove a letter)
60-
# to cause jitpack to regenerate the artifact.
61-
teamnewpipe-newpipe-extractor = "3af73262cc60cf555fd5f1d691f6c58e2db38ef5"
56+
# The NewPipeExtractor commit hash is used in settings.gradle.kts to depend on the NewPipeExtractor
57+
# git repositories directly. nanojson and filepicker use incompatible build systems so we still rely
58+
# on Jitpack for those two.
59+
# If you want to use a local copy of NewPipeExtractor (provided that you have cloned it in
60+
# `../NewPipeExtractor`), you can add `useLocalNewPipeExtractor=true` in `local.properties`.
61+
# Or you use a commit you pushed to GitHub by just replacing TeamNewPipe with your GitHub
62+
# name in settings.gradle.kts and update the commit hash here with the commit hash of the
63+
# (pushed) commit you want to test.
64+
teamnewpipe-newpipeextractor = "724cc46f422a647884021d156bb0242784309843"
6265
viewpager2 = "1.1.0"
6366
webkit = "1.14.0"
6467
work = "2.10.5" # Newer versions require minSdk >= 23
@@ -113,9 +116,6 @@ lisawray-groupie-core = { module = "com.github.lisawray.groupie:groupie", versio
113116
lisawray-groupie-viewbinding = { module = "com.github.lisawray.groupie:groupie-viewbinding", version.ref = "groupie" }
114117
livefront-bridge = { module = "com.github.livefront:bridge", version.ref = "bridge" }
115118
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockitoCore" }
116-
newpipe-extractor = { module = "com.github.TeamNewPipe:NewPipeExtractor", version.ref = "teamnewpipe-newpipe-extractor" }
117-
newpipe-filepicker = { module = "com.github.TeamNewPipe:NoNonsense-FilePicker", version.ref = "teamnewpipe-filepicker" }
118-
newpipe-nanojson = { module = "com.github.TeamNewPipe:nanojson", version.ref = "teamnewpipe-nanojson" }
119119
noties-markwon-core = { module = "io.noties.markwon:core", version.ref = "markwon" }
120120
noties-markwon-linkify = { module = "io.noties.markwon:linkify", version.ref = "markwon" }
121121
ocpsoft-prettytime = { module = "org.ocpsoft.prettytime:prettytime", version.ref = "prettytime" }
@@ -128,6 +128,9 @@ squareup-leakcanary-plumber = { module = "com.squareup.leakcanary:plumber-androi
128128
squareup-leakcanary-watcher = { module = "com.squareup.leakcanary:leakcanary-object-watcher-android", version.ref = "leakcanary" }
129129
squareup-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
130130
squareup-picasso = { module = "com.squareup.picasso:picasso", version.ref = "picasso" }
131+
teamnewpipe-extractor = { module = "git.included.build:NewPipeExtractor" }
132+
teamnewpipe-filepicker = { module = "com.github.TeamNewPipe:NoNonsense-FilePicker", version.ref = "teamnewpipe-filepicker" }
133+
teamnewpipe-nanojson = { module = "com.github.TeamNewPipe:nanojson", version.ref = "teamnewpipe-nanojson" }
131134

132135
[plugins]
133136
android-application = { id = "com.android.application", version.ref = "agp" }

settings.gradle.kts

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
33
* SPDX-License-Identifier: GPL-3.0-or-later
44
*/
5+
import me.champeau.gradle.igp.gitRepositories
6+
import org.eclipse.jgit.api.Git
7+
import java.io.FileInputStream
8+
import java.util.Properties
59

610
pluginManagement {
711
repositories {
@@ -10,6 +14,20 @@ pluginManagement {
1014
mavenCentral()
1115
}
1216
}
17+
18+
plugins {
19+
// need to manually read version catalog because it is not available in settings.gradle.kts
20+
// this code is duplicate with the below but there is no way to avoid it...
21+
fun findInVersionCatalog(versionIdentifier: String): String {
22+
val regex = "^.*$versionIdentifier *= *\"([^\"]+)\".*$".toRegex()
23+
return File("gradle/libs.versions.toml")
24+
.readLines()
25+
.firstNotNullOf { regex.find(it)?.groupValues?.get(1) }
26+
}
27+
28+
id("me.champeau.includegit") version findInVersionCatalog("includegitPlugin")
29+
}
30+
1331
dependencyResolutionManagement {
1432
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
1533
repositories {
@@ -21,13 +39,85 @@ dependencyResolutionManagement {
2139
}
2240
include (":app")
2341

24-
// Use a local copy of NewPipe Extractor by uncommenting the lines below.
25-
// We assume, that NewPipe and NewPipe Extractor have the same parent directory.
26-
// If this is not the case, please change the path in includeBuild().
2742

28-
//includeBuild("../NewPipeExtractor") {
29-
// dependencySubstitution {
30-
// substitute(module("com.github.TeamNewPipe:NewPipeExtractor"))
31-
// .using(project(":extractor"))
32-
// }
33-
//}
43+
// All of the code below handles depending on libraries from git repos, in particular
44+
// NewPipeExtractor. The git commit to checkout can be updated in libs.versions.toml.
45+
// If you want to use a local copy of NewPipeExtractor (provided that you have cloned it in
46+
// `../NewPipeExtractor`), you can add `useLocalNewPipeExtractor=true` to `local.properties`.
47+
// Or you use a commit you pushed to GitHub by just replacing TeamNewPipe with your GitHub
48+
// name below here and update the commit hash in libs.versions.toml with the commit hash of the
49+
// (pushed) commit you want to test.
50+
51+
data class IncludeGitRepo(
52+
val name: String,
53+
val uri: String,
54+
val projectPath: String,
55+
val commit: String,
56+
)
57+
58+
// need to manually read version catalog because it is not available in settings.gradle.kts
59+
// this code is duplicate with the above but there is no way to avoid it...
60+
fun findInVersionCatalog(versionIdentifier: String): String {
61+
val regex = "^.*$versionIdentifier *= *\"([^\"]+)\".*$".toRegex()
62+
return File("gradle/libs.versions.toml")
63+
.readLines()
64+
.firstNotNullOf { regex.find(it)?.groupValues?.get(1) }
65+
}
66+
67+
val newPipeExtractor = IncludeGitRepo(
68+
name = "NewPipeExtractor",
69+
uri = "https://github.com/TeamNewPipe/NewPipeExtractor",
70+
projectPath = ":extractor",
71+
commit = findInVersionCatalog("teamnewpipe-newpipeextractor"),
72+
)
73+
74+
val localProperties = Properties().apply {
75+
try {
76+
load(FileInputStream(File(rootDir, "local.properties")))
77+
} catch (e: Throwable) {
78+
println("Warning: can't read local.properties: $e")
79+
}
80+
}
81+
82+
if (localProperties.getOrDefault("useLocalNewPipeExtractor", "") == "true") {
83+
includeBuild("../${newPipeExtractor.name}") {
84+
dependencySubstitution {
85+
substitute(module("git.included.build:${newPipeExtractor.name}"))
86+
.using(project(newPipeExtractor.projectPath))
87+
}
88+
}
89+
90+
} else {
91+
// if the repo has already been cloned, the gitRepositories plugin is buggy and doesn't
92+
// fetch the remote repo before trying to checkout the commit (in case the commit has changed),
93+
// and doesn't clone the repo again if the remote changed, so we need to do it manually
94+
val repo = newPipeExtractor
95+
val file = File("$rootDir/checkouts/${repo.name}")
96+
if (file.isDirectory) {
97+
val git = Git.open(file)
98+
val sameRemote = git.remoteList().call()
99+
.any { rem -> rem.urIs.any { uri -> uri.toString() == repo.uri } }
100+
if (sameRemote) {
101+
// the commit may have changed, fetch again
102+
git.fetch().call()
103+
} else {
104+
// the remote changed, delete the repository and start from scratch
105+
println("Git: remote for ${repo.name} changed, deleting the current folder")
106+
file.deleteRecursively()
107+
}
108+
}
109+
110+
gitRepositories {
111+
include(repo.name) {
112+
uri.set(repo.uri)
113+
commit.set(repo.commit)
114+
autoInclude.set(false)
115+
includeBuild("") {
116+
dependencySubstitution {
117+
substitute(module("git.included.build:${repo.name}"))
118+
.using(project(repo.projectPath))
119+
}
120+
}
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)