Skip to content

Commit

Permalink
feat: updated Gradle to 7.2. Added Android 12 support. Fixed NPE. (#26)
Browse files Browse the repository at this point in the history
* feat: updated Gradle to 7.2. Added Android 12 support. Fixed NPE.

* fix: skip unsupported Android API 31 android tests

* ci: only assemble debug
  • Loading branch information
gotev authored Nov 4, 2021
1 parent ed88015 commit 7c046d4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 31 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ on:
jobs:
android-test:
runs-on: macos-latest

if: ${{ false }} # skip job as it currently does not support Android API 31
steps:
- name: checkout
uses: actions/checkout@v2

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
api-level: 31
script: ./gradlew connectedCheck

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Build with Gradle
run: ./gradlew clean build

Expand All @@ -37,9 +37,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
- name: set up JDK
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Build with Gradle
run: cd example && ./gradlew clean build
run: cd example && ./gradlew clean assembleDebug
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ open class InMemoryCookieStore(private val name: String) : CookieStore {

lock.lock()
try {
cookies.addAll(getInternal1(uri.host))
uri.host?.let { cookies.addAll(getInternal1(it)) }
val internal2 = getInternal2(getEffectiveURI(uri)).filter { !cookies.contains(it) }
cookies.addAll(internal2)
} finally {
Expand Down
7 changes: 3 additions & 4 deletions example/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jlleitschuh.gradle.ktlint"

android {
Expand Down Expand Up @@ -33,9 +32,9 @@ dependencies {
testImplementation "junit:junit:$junit_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

def gander_version = "3.1.0"
debugImplementation "com.ashokvarma.android:gander-imdb:$gander_version"
releaseImplementation "com.ashokvarma.android:gander-no-op:$gander_version"
def chucker_version = "3.5.2"
debugImplementation "com.github.chuckerteam.chucker:library:$chucker_version"
releaseImplementation "com.github.chuckerteam.chucker:library-no-op:$chucker_version"

// Core library
androidTestImplementation "androidx.test:core:$androidx_test_core_version"
Expand Down
4 changes: 3 additions & 1 deletion example/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
8 changes: 2 additions & 6 deletions example/app/src/main/java/net/gotev/cookiestoredemo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package net.gotev.cookiestoredemo

import android.app.Application
import android.util.Log
import com.ashokvarma.gander.Gander
import com.ashokvarma.gander.GanderInterceptor
import com.ashokvarma.gander.imdb.GanderIMDB
import com.chuckerteam.chucker.api.ChuckerInterceptor
import net.gotev.cookiestore.InMemoryCookieStore
import net.gotev.cookiestore.SharedPreferencesCookieStore
import net.gotev.cookiestore.WebKitSyncCookieManager
Expand Down Expand Up @@ -52,12 +50,10 @@ class App : Application() {
// Setup for HttpURLConnection
CookieManager.setDefault(cookieManager)

Gander.setGanderStorage(GanderIMDB.getInstance())

// Setup for OkHttp
val okHttpClient = OkHttpClient.Builder()
.cookieJar(JavaNetCookieJar(cookieManager))
.addNetworkInterceptor(GanderInterceptor(this).showNotification(true))
.addNetworkInterceptor(ChuckerInterceptor.Builder(this).build())
.build()

cookieAPI = Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.os.Bundle
import android.util.Log
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

Expand All @@ -22,7 +22,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

// login sends back a cookie
login.setOnClickListener {
findViewById<Button>(R.id.login).setOnClickListener {
scope.launch {
try {
App.cookieAPI.login(LoginPayload(username = App.username))
Expand All @@ -35,7 +35,7 @@ class MainActivity : AppCompatActivity() {
}

// home call sends the cookie back to the server if present
login_status.setOnClickListener {
findViewById<Button>(R.id.login_status).setOnClickListener {
scope.launch {
try {
val message = App.cookieAPI.home()
Expand All @@ -47,13 +47,13 @@ class MainActivity : AppCompatActivity() {
}

// this clears all the cookies
clearCookies.setOnClickListener {
findViewById<Button>(R.id.clearCookies).setOnClickListener {
App.cookieManager.removeAll()
toast("Cookies Cleared!")
reloadUrl()
}

webView.webViewClient = object : WebViewClient() {
findViewById<WebView>(R.id.webView).webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
try {
val cookie = android.webkit.CookieManager.getInstance().getCookie(url)
Expand All @@ -75,6 +75,6 @@ class MainActivity : AppCompatActivity() {

// load home in webview to check cookie sync
private fun reloadUrl() {
webView.loadUrl(App.webViewUrl)
findViewById<WebView>(R.id.webView).loadUrl(App.webViewUrl)
}
}
2 changes: 1 addition & 1 deletion example/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
8 changes: 4 additions & 4 deletions manifest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ ext {
library_licenses = ["Apache-2.0"]
library_licenses_url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
library_project_group = 'net.gotev'
library_version = '1.3.5'
library_version = '1.4.0'
version_code = 3
min_sdk = 16
target_sdk = 30
target_sdk = 31
demo_app_id = 'net.gotev.cookiestoredemo'

// Gradle classpath dependencies versions
kotlin_version = '1.4.0'
gradle_version = '4.1.2'
kotlin_version = '1.4.32'
gradle_version = '7.0.3'
kotlin_lint_version = '9.0.0'

// Library and app testing dependencies versions
Expand Down

0 comments on commit 7c046d4

Please sign in to comment.