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

Upgrading the repo dependencies and tooling to current android standards #213

Merged
merged 9 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
java-version: '17'
lalwani marked this conversation as resolved.
Show resolved Hide resolved
- name: Lint and Unit tests
run: ./gradlew check --stacktrace
- name: Upload lint and test reports
Expand All @@ -25,7 +25,6 @@ jobs:
path: |
./core-android/build/reports
./rides-android/build/reports

test:
runs-on: macOS-latest # enables hardware acceleration in the virtual machine, required for emulator testing
strategy:
Expand All @@ -40,7 +39,7 @@ jobs:
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
java-version: '17'
- name: Emulator tests
uses: reactivecircus/android-emulator-runner@v2
with:
Expand All @@ -57,7 +56,6 @@ jobs:
path: |
./core-android/build/reports
./rides-android/build/reports

upload-snapshots:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
Expand All @@ -73,9 +71,9 @@ jobs:
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
java-version: '17'
- name: Upload snapshots
run: ./gradlew uploadArchives --stacktrace
run: ./gradlew publish --stacktrace
env:
ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.SonatypeUsername }}
ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SonatypePassword }}
ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SonatypePassword }}
122 changes: 122 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.LibraryExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import java.net.URI

plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.dokka)
}

val compileSdkVersionInt: Int = libs.versions.compileSdkVersion.get().toInt()
val targetSdkVersion: Int = libs.versions.targetSdkVersion.get().toInt()
val minSdkVersion: Int = libs.versions.minSdkVersion.get().toInt()
val jvmTargetVersion = libs.versions.jvmTarget

tasks.dokkaHtmlMultiModule {
outputDirectory.set(rootDir.resolve("docs/api/2.x"))
includes.from(project.layout.projectDirectory.file("README.md"))
}

subprojects {

val commonAndroidConfig: CommonExtension<*, *, *, *>.() -> Unit = {
compileSdk = compileSdkVersionInt

defaultConfig {
minSdk = minSdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.toVersion(jvmTargetVersion.get())
targetCompatibility = JavaVersion.toVersion(jvmTargetVersion.get())
}
lint {
checkTestSources = true
val lintXml = file("lint.xml")
if (lintXml.exists()) {
lintConfig = lintXml
}
}
}

pluginManager.withPlugin("com.android.library") {

Choose a reason for hiding this comment

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

Have you considered the includedBuilds approach for configuring the modules? As we did in RIBs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't looked at how it's done in RIBs repo so not sure what you mean.
What's the benefit? I can check it later and update the gradle file if needed

project.configure<LibraryExtension> {
commonAndroidConfig()
defaultConfig { consumerProguardFiles("consumer-proguard-rules.txt") }
testBuildType = "release"
configure<LibraryAndroidComponentsExtension> {
beforeVariants(selector().withBuildType("debug")) { builder -> builder.enable = false }
}
}
}

pluginManager.withPlugin("com.android.application") {
project.configure<ApplicationExtension> {
commonAndroidConfig()
configure<ApplicationAndroidComponentsExtension> {
// Only debug enabled for this one
beforeVariants { builder ->
builder.enable = builder.buildType != "release"
builder.enableAndroidTest = false
builder.enableUnitTest = false
}
}
}
}

pluginManager.withPlugin("com.vanniktech.maven.publish") {
project.apply(plugin = "org.jetbrains.dokka")

tasks.withType<DokkaTaskPartial>().configureEach {
outputDirectory.set(buildDir.resolve("docs/partial"))
moduleName.set(project.property("POM_ARTIFACT_ID").toString())
moduleVersion.set(project.property("VERSION_NAME").toString())
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
suppressGeneratedFiles.set(true)
suppressInheritedMembers.set(true)
externalDocumentationLink {
url.set(URI("https://kotlin.github.io/kotlinx.coroutines/index.html").toURL())
}
perPackageOption {
// language=RegExp
matchingRegex.set(".*\\.internal\\..*")
suppress.set(true)
}
val moduleMd = project.layout.projectDirectory.file("README.md")
if (moduleMd.asFile.exists()) {
includes.from(moduleMd)
}
}
}

configure<MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = false)
signAllPublications()
}
}
}
71 changes: 0 additions & 71 deletions core-android/build.gradle

This file was deleted.

54 changes: 54 additions & 0 deletions core-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.mavenPublish)
}

android {
namespace = "com.uber.sdk.android.core"
buildFeatures {
buildConfig = true
}

defaultConfig {
testApplicationId = "com.uber.sdk.android.core"
buildConfigField("String", "VERSION_NAME", "\"${project.property("VERSION_NAME").toString()}\"")
}
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

dependencies {
implementation(libs.uberCore) {
exclude(group = "org.slf4j", module = "slf4j-log4j12")
}
implementation(libs.jsr305)
implementation(libs.appCompat)
implementation(libs.annotations)
implementation(libs.chrometabs)

testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.mockito)
testImplementation(libs.robolectric)
testImplementation(project(":core-android"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void setBackgroundAttributes(
int attrsResources[] = {
android.R.attr.background,
};
TypedArray backgroundAttributes = context.getTheme().obtainStyledAttributes(
@SuppressLint("ResourceType") TypedArray backgroundAttributes = context.getTheme().obtainStyledAttributes(
attrs,
attrsResources,
defStyleAttr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ protected void loadWebview(String url, String redirectUri) {
setContentView(R.layout.ub__login_activity);
webView = (WebView) findViewById(R.id.ub__login_webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(createOAuthClient(redirectUri));
webView.loadUrl(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import android.util.Log;

lalwani marked this conversation as resolved.
Show resolved Hide resolved
import com.uber.sdk.android.core.BuildConfig;
import com.uber.sdk.android.core.Deeplink;
import com.uber.sdk.android.core.SupportedAppType;
Expand Down
4 changes: 4 additions & 0 deletions core-android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
<item name="android:background">@drawable/uber_button_background_selector_white</item>
<item name="android:drawableLeft">@drawable/uber_logotype_black</item>
</style>

<style name="UberButton.Background">
<item name="android:background">?android:attr/background</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 21)
@Config(sdk = 26)
lalwani marked this conversation as resolved.
Show resolved Hide resolved
public abstract class RobolectricTestBase {

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;

import org.apache.maven.artifact.ant.shaded.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.robolectric.Robolectric;
Expand Down Expand Up @@ -178,7 +178,7 @@ public void onCreate_whenNoAttributesSet_shouldUseUberButtonDefaults() {

assertEquals(resources.getColor(R.color.uber_white), uberButton.getCurrentTextColor());
assertEquals(Typeface.NORMAL, uberButton.getTypeface().getStyle());
assertTrue(StringUtils.isEmpty(uberButton.getText().toString()));
assertTrue(TextUtils.isEmpty(uberButton.getText().toString()));
}

@Test
Expand All @@ -205,7 +205,7 @@ public void onCreate_whenUberStyleSet_shouldUseUberStyle() {
assertEquals(resources.getColor(R.color.uber_black), uberButton.getCurrentTextColor());
assertEquals(Typeface.NORMAL, uberButton.getTypeface().getStyle());
assertTrue(uberButton.getGravity() != 0);
assertTrue(StringUtils.isEmpty(uberButton.getText().toString()));
assertTrue(TextUtils.isEmpty(uberButton.getText().toString()));
}

@Test
Expand Down
Loading
Loading