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

feat(android): add error handling for Kotlin version mismatch #4018

36 changes: 34 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,39 @@ buildscript {
}
}

// This looks funny but it's necessary to keep backwards compatibility (:
task checkKotlinVersion {
doLast {
def kotlinVersion = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNVideo_kotlinVersion']
def requiredKotlinVersion = project.properties['RNVideo_requiredKotlinVersion']
KrzysztofMoch marked this conversation as resolved.
Show resolved Hide resolved

// Function to compare version strings
def isVersionAtLeast = { version, requiredVersion ->
def (v1, v2) = [version, requiredVersion].collect { it.tokenize('.')*.toInteger() }
for (int i = 0; i < Math.max(v1.size(), v2.size()); i++) {
int val1 = i < v1.size() ? v1[i] : 0
int val2 = i < v2.size() ? v2[i] : 0
if (val1 < val2) {
return false
} else if (val1 > val2) {
return true
}
}
return true
}

if (!isVersionAtLeast(kotlinVersion, requiredKotlinVersion)) {
throw new GradleException("Kotlin version mismatch: Project is using Kotlin version $kotlinVersion, but it must be at least $requiredKotlinVersion. Please update the Kotlin version.")
} else {
println("Kotlin version is correct: $kotlinVersion")
}
}
}

tasks.matching { it.name.startsWith('pre') || it.name == 'compileDebugKotlin' }.all {
dependsOn checkKotlinVersion
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we need to do it that we - we can convert checkKotlinVersion task to function and call this function eg. in buildscript or somewhere else

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's refactored.


// This looks funny but it's necessary to keep backwards compatibility (:
def safeExtGet(prop) {
return rootProject.ext.has(prop) ?
rootProject.ext.get(prop) : rootProject.ext.has("RNVideo_" + prop) ?
Expand Down Expand Up @@ -239,7 +271,7 @@ dependencies {
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
}
}

// For ad insertion using the Interactive Media Ads SDK with ExoPlayer
if (ExoplayerDependencies["useExoplayerIMA"]) {
if (media3_buildFromSource) {
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ RNVideo_useExoplayerHls=true
RNVideo_androidxCoreVersion=1.9.0
RNVideo_androidxActivityVersion=1.7.0
RNVideo_buildFromMedia3Source=false
RNVideo_requiredKotlinVersion=1.9.0
KrzysztofMoch marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ class FullScreenPlayerView(
parent = null
}

private fun getFullscreenIconResource(isFullscreen: Boolean): Int {
return if (isFullscreen) {
private fun getFullscreenIconResource(isFullscreen: Boolean): Int =
if (isFullscreen) {
androidx.media3.ui.R.drawable.exo_icon_fullscreen_exit
} else {
androidx.media3.ui.R.drawable.exo_icon_fullscreen_enter
}
}

private fun updateFullscreenButton(playerControlView: LegacyPlayerControlView, isFullscreen: Boolean) {
val imageButton = playerControlView.findViewById<ImageButton?>(com.brentvatne.react.R.id.exo_fullscreen)
Expand Down
Loading