SQLite Forum

SQLite Android Bindings instructions are out of date
Login

SQLite Android Bindings instructions are out of date

(1) By Heath Borders (heathborders) on 2020-06-28 05:57:09 [link] [source]

Instructions for building a custom AAR file are out of date starting at step 4.

Obsolete NDK

First, the project uses the now obsolete NDK instead of the Side by side NDK. When I check try to build the project with ./gradlew assembleRelease, it fails with the following error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':sqlite3'.
> NDK not configured.
  Download it with SDK manager.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s

I solved the problem by installing the NDK (Obsolete) package within Android Studio.

I've detailed this on stackoverflow.

Missing Maven Repo

Second, the project fails to resolve com.android.support:appcompat-v7:23.4.0 because it is missing the google() repository in its build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        // google() // <-- this line is missing from the current source
                    // uncommenting it allows gradle to resolve
                    // com.android.support:appcompat-v7:23.4.0
                    // for the `sqlite3test` project
    }
}

I detailed this on stackoverflow.

Thanks!

Thanks so much for this project! I've depended on your great work for my entire 12 years as a mobile developer.

(2) By Heath Borders (heathborders) on 2020-07-01 05:04:12 in reply to 1 [link] [source]

I've fixed the above problems, but I don't see anything on the site that lists a way to contribute fixes upstream. Is it possible for me to contribute upstream fixes for this?

(3) By Warren Young (wyoung) on 2020-07-01 06:25:46 in reply to 2 [link] [source]

I don't see anything on the site that lists a way to contribute fixes upstream.

We had this topic here just yesterday.

There's a pretty good search engine attached to this forum, too.

(4.1) By Dan Kennedy (dan) on 2020-07-01 14:40:57 edited from 4.0 in reply to 2 [link] [source]

It's clear enough how to add the missing repository, but how do we fix the obsolete NDK issue?

A patch would be great if you have one!

Thanks,

Dan.

(5) By Heath Borders (heathborders) on 2020-07-01 22:39:07 in reply to 4.1 [link] [source]

I modernized the project last night, and got rid of the obsolete NDK. What is the best way to submit a patch? The Contributed Code section of the Copyright document says that SQLite doesn't accept outside patches, and I don't see a way to attach files to this forum.

Thank you for your patience with me. I'm a long-time listener, first-time caller. :)

(6) By Warren Young (wyoung) on 2020-07-01 22:41:50 in reply to 5 [link] [source]

I don't see a way to attach files to this forum.

2 messages up from the one I linked you to yesterday, drh said...

(7) By Richard Hipp (drh) on 2020-07-01 23:18:59 in reply to 5 [source]

Please just copy/paste your changes in-line.

We won't use your patches directly. But we will use them to better understand the problem you are having.

(8.1) By Heath Borders (heathborders) on 2020-07-02 02:55:10 edited from 8.0 in reply to 4.1 [link] [source]

I still want to update from .mk files to cmake, which Android NDK prefers, but this patch at least makes everything compatible with modern Android. This does not fix the broken sqlite3/src/androidTest/java tests, which I'm still investigating.

Modernized dependencies:

Gradle 6.5.1

AGP 4.0.0

target and compile SDK 29

Updated to AndroidX

Changed NDK to side-by-side

new file mode 100644
index 0000000..b6a19e6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/.gradle
+/build
+/local.properties
diff --git a/build.gradle b/build.gradle
index 63db7bf..7d34715 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.4'
+        classpath 'com.android.tools.build:gradle:4.0.0'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
@@ -16,6 +16,7 @@ buildscript {
 allprojects {
     repositories {
         jcenter()
+        google()
     }
 }
 
diff --git a/gradle.properties b/gradle.properties
index c04c048..223c6a0 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -17,3 +17,5 @@
 # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
 # org.gradle.parallel=true
 
+android.enableJetifier=true
+android.useAndroidX=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5183492..85801fc 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -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-4.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
diff --git a/gradlew b/gradlew
old mode 100644
new mode 100755
diff --git a/sqlite3/.gitignore b/sqlite3/.gitignore
new file mode 100644
index 0000000..e249f22
--- /dev/null
+++ b/sqlite3/.gitignore
@@ -0,0 +1,3 @@
+/.externalNativeBuild
+build
+.cxx
diff --git a/sqlite3/build.gradle b/sqlite3/build.gradle
index 4210136..ad53fb9 100644
--- a/sqlite3/build.gradle
+++ b/sqlite3/build.gradle
@@ -1,13 +1,14 @@
 apply plugin: 'com.android.library'
 
 android {
-    compileSdkVersion 25
+    compileSdkVersion 29
 
     defaultConfig {
         minSdkVersion 16
+        targetSdkVersion 29
         versionCode 1
         versionName "1.0"
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
     }
 
     buildTypes {
@@ -32,14 +33,19 @@ android {
             path 'src/main/jni/Android.mk'
         }
     }
+
+    ndkVersion "21.3.6528147"
+
+    useLibrary 'android.test.base' // for android.test.AndroidTestCase
+    useLibrary 'android.test.runner' // for android.test.MoreAsserts
 }
 
 dependencies {
-    compile fileTree(include: ['*.jar'], dir: 'libs')
-    androidTestCompile 'com.android.support:support-annotations:24.0.0'
-    androidTestCompile 'com.android.support.test:runner:0.5'
-    androidTestCompile 'com.android.support.test:rules:0.5'
-    testCompile 'junit:junit:4.12'
+    implementation fileTree(include: ['*.jar'], dir: 'libs')
+    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test:rules:1.2.0'
+    testImplementation 'junit:junit:4.13'
 }
 
 allprojects {
@@ -48,4 +54,4 @@ allprojects {
         google()
         jcenter()
     }
-}
\ No newline at end of file
+}
diff --git a/sqlite3/src/androidTest/java/org/sqlite/database/SeeTest1.java b/sqlite3/src/androidTest/java/org/sqlite/database/SeeTest1.java
index 0e65657..d2a0536 100644
--- a/sqlite3/src/androidTest/java/org/sqlite/database/SeeTest1.java
+++ b/sqlite3/src/androidTest/java/org/sqlite/database/SeeTest1.java
@@ -3,9 +3,8 @@ package org.sqlite.database;
 import android.content.Context;
 import android.database.Cursor;
 import android.os.AsyncTask;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-import android.util.Log;
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
 
 import junit.framework.Assert;
 
@@ -21,8 +20,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.util.Arrays;
 
-import static org.junit.Assert.*;
-
 
 class MyHelper extends SQLiteOpenHelper {
 
@@ -75,7 +72,7 @@ public class SeeTest1 {
 
         System.loadLibrary("sqliteX");
 
-        mContext = InstrumentationRegistry.getTargetContext();
+        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
 
         // delete any existing database
         File databaseFile = mContext.getDatabasePath(MyHelper.DATABASE_NAME);
diff --git a/sqlite3/src/androidTest/java/org/sqlite/database/sqlite_cts/SQLiteStatementTest.java b/sqlite3/src/androidTest/java/org/sqlite/database/sqlite_cts/SQLiteStatementTest.java
index b601405..dd98914 100644
--- a/sqlite3/src/androidTest/java/org/sqlite/database/sqlite_cts/SQLiteStatementTest.java
+++ b/sqlite3/src/androidTest/java/org/sqlite/database/sqlite_cts/SQLiteStatementTest.java
@@ -18,7 +18,6 @@ package org.sqlite.database.sqlite_cts;
 
 
 import android.content.ContentValues;
-import android.content.Context;
 import android.database.Cursor;
 import org.sqlite.database.DatabaseUtils;
 import org.sqlite.database.SQLException;
@@ -26,7 +25,7 @@ import org.sqlite.database.sqlite.SQLiteDatabase;
 import org.sqlite.database.sqlite.SQLiteDoneException;
 import org.sqlite.database.sqlite.SQLiteStatement;
 import android.os.ParcelFileDescriptor;
-import android.support.test.filters.Suppress;
+import androidx.test.filters.Suppress;
 import android.test.AndroidTestCase;
 import android.test.MoreAsserts;
 
diff --git a/sqlite3test/.gitignore b/sqlite3test/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/sqlite3test/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/sqlite3test/build.gradle b/sqlite3test/build.gradle
index c82a2d3..8c711b8 100644
--- a/sqlite3test/build.gradle
+++ b/sqlite3test/build.gradle
@@ -1,12 +1,12 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 23
+    compileSdkVersion 29
 
     defaultConfig {
         applicationId "org.sqlite.customsqlitetest"
         minSdkVersion 16
-        targetSdkVersion 23
+        targetSdkVersion 29
         versionCode 1
         versionName "1.0"
     }
@@ -16,11 +16,16 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
+
+    ndkVersion "21.3.6528147"
+
+    useLibrary 'android.test.base' // for android.test.AndroidTestCase
+    useLibrary 'android.test.runner' // for android.test.ApplicationTestCase extends AndroidTestCase
 }
 
 dependencies {
-    compile fileTree(include: ['*.jar'], dir: 'libs')
-    testCompile 'junit:junit:4.12'
-    compile 'com.android.support:appcompat-v7:23.4.0'
-    compile project(':sqlite3')
+    implementation fileTree(include: ['*.jar'], dir: 'libs')
+    testImplementation 'junit:junit:4.13'
+    implementation 'androidx.appcompat:appcompat:1.1.0'
+    implementation project(':sqlite3')
 }
diff --git a/sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java b/sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java
index 2fff126..b61cd08 100644
--- a/sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java
+++ b/sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java
@@ -3,7 +3,7 @@ package org.sqlite.customsqlitetest;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
-import android.support.v7.app.AppCompatActivity;
+import androidx.appcompat.app.AppCompatActivity;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;

(9) By Dan Kennedy (dan) on 2020-07-02 15:52:08 in reply to 8.1 [link] [source]

this patch at least makes everything compatible with modern Android.

Thanks! Now applied here:

https://sqlite.org/android/info/a742d49c4cb4e3fc