SQLite Android Bindings

Check-in [a742d49c4c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Upgrade this project to more modern Android dependencies. This patch is from Heath Borders on the mailing list.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a742d49c4cb4e3fc09da051e6e346fb5e1dda0f2
User & Date: dan 2020-07-02 15:50:10.093
Context
2020-08-14
13:44
Update to version 3.33.0. (check-in: 5177495302 user: dan tags: trunk)
2020-07-02
15:50
Upgrade this project to more modern Android dependencies. This patch is from Heath Borders on the mailing list. (check-in: a742d49c4c user: dan tags: trunk)
15:48
Update build documentation to match previous commit. (Closed-Leaf check-in: 1ca2ebe562 user: dan tags: upgrade)
15:05
Upgrade this project to version 3.32.3. (check-in: 060a7b4769 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to build.gradle.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
// Top-level build file where you can add configuration options common to all sub-projects/modules.

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()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}








|









>






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        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
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Changes to gradle.properties.
13
14
15
16
17
18
19


# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true










>
>
13
14
15
16
17
18
19
20
21
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.enableJetifier=true
android.useAndroidX=true
Changes to gradle/wrapper/gradle-wrapper.properties.
1
2
3
4
5
6
#Tue Sep 04 03:46:04 ICT 2018
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





|
1
2
3
4
5
6
#Tue Sep 04 03:46:04 ICT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
Changes to sqlite3/build.gradle.
1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
apply plugin: 'com.android.library'

android {
    compileSdkVersion 25

    defaultConfig {
        minSdkVersion 16

        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }



|



>


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apply plugin: 'com.android.library'

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
28
29
30
31
32
33
34





35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

    //sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }





}

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'
}

allprojects {
    repositories {
        // The order in which you list these repositories matter.
        google()
        jcenter()
    }
}







>
>
>
>
>



|
|
|
|
|









29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

    //sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
    externalNativeBuild {
        ndkBuild {
            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 {
    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 {
    repositories {
        // The order in which you list these repositories matter.
        google()
        jcenter()
    }
}
Changes to sqlite3/src/androidTest/java/org/sqlite/database/SeeTest1.java.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.sqlite.database.sqlite.SQLiteConnection;
import org.sqlite.database.sqlite.SQLiteDatabase;
import org.sqlite.database.sqlite.SQLiteOpenHelper;

import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;

import static org.junit.Assert.*;


class MyHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "mydb.db";

    public MyHelper(Context ctx){
        super(ctx, "file:" + ctx.getDatabasePath(DATABASE_NAME).getAbsolutePath() + "?key=secret", null, 1);





|
<
|















<
<







1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
package org.sqlite.database;

import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import androidx.test.platform.app.InstrumentationRegistry;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.sqlite.database.sqlite.SQLiteConnection;
import org.sqlite.database.sqlite.SQLiteDatabase;
import org.sqlite.database.sqlite.SQLiteOpenHelper;

import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;




class MyHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "mydb.db";

    public MyHelper(Context ctx){
        super(ctx, "file:" + ctx.getDatabasePath(DATABASE_NAME).getAbsolutePath() + "?key=secret", null, 1);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    }

    @Before
    public void setup() throws Exception {

        System.loadLibrary("sqliteX");

        mContext = InstrumentationRegistry.getTargetContext();

        // delete any existing database
        File databaseFile = mContext.getDatabasePath(MyHelper.DATABASE_NAME);
        databaseFile.mkdirs();
        if (databaseFile.exists()) {
            databaseFile.delete();
        }







|







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    }

    @Before
    public void setup() throws Exception {

        System.loadLibrary("sqliteX");

        mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        // delete any existing database
        File databaseFile = mContext.getDatabasePath(MyHelper.DATABASE_NAME);
        databaseFile.mkdirs();
        if (databaseFile.exists()) {
            databaseFile.delete();
        }
Changes to sqlite3/src/androidTest/java/org/sqlite/database/sqlite_cts/SQLiteStatementTest.java.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * limitations under the License.
 */

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;
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 android.test.AndroidTestCase;
import android.test.MoreAsserts;

import java.io.IOException;
import java.io.InputStream;
import java.io.File;








<







|







14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * limitations under the License.
 */

package org.sqlite.database.sqlite_cts;


import android.content.ContentValues;

import android.database.Cursor;
import org.sqlite.database.DatabaseUtils;
import org.sqlite.database.SQLException;
import org.sqlite.database.sqlite.SQLiteDatabase;
import org.sqlite.database.sqlite.SQLiteDoneException;
import org.sqlite.database.sqlite.SQLiteStatement;
import android.os.ParcelFileDescriptor;
import androidx.test.filters.Suppress;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;

import java.io.IOException;
import java.io.InputStream;
import java.io.File;

Changes to sqlite3test/build.gradle.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18





19
20
21
22
23
24
25
26
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23

    defaultConfig {
        applicationId "org.sqlite.customsqlitetest"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }





}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(':sqlite3')
}



|




|









>
>
>
>
>



|
|
|
|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "org.sqlite.customsqlitetest"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            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 {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.13'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation project(':sqlite3')
}
Changes to sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java.
1
2
3
4
5
6
7
8
9
10
11
12
13
package org.sqlite.customsqlitetest;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import org.json.JSONObject;
import org.sqlite.database.DatabaseErrorHandler;





|







1
2
3
4
5
6
7
8
9
10
11
12
13
package org.sqlite.customsqlitetest;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import org.json.JSONObject;
import org.sqlite.database.DatabaseErrorHandler;
Changes to www/install.wiki.
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
    -DSQLITE_ENABLE_JSON1
    -DSQLITE_ENABLE_FTS3</verbatim>
  To build the SQLite library with some other combination of command line
  switches, edit the <code>Android.mk</code> file at this location:
<verbatim>
    sqlite3/src/main/jni/sqlite/Android.mk</verbatim>

<li><a name=buildnative2></a> <b>Build the native libraries.</b>
<p>
This step is <b>optional. It will be run automatically by the
</b><code>gradlew</code><b> command in step 4.</b> Running it separately
is primarily useful for for debugging broken builds.
  <p> To build the native libraries, navigate to the
      <code>sqlite3/src/main/</code> directory of the project directory and
      run the <code>ndk-build</code> command. For example, on Linux if 
      Android Studio and the NDK are installed using their default paths:
<verbatim>
    $ cd sqlite3/src/main
    $ ~/Android/Sdk/ndk-bundle/ndk-build</verbatim>
  <p> On modern hardware, this command takes roughly 3 minutes to build the
      native libraries for all Android architectures.
  <p>
  If the <code>Android.mk</code> file is edited after <code>ndk-build</code> is
  run, it may be necessary to run the <code>ndk-build clean</code> command
  before rerunning <code>ndk-build</code> to ensure a correct build.

  <li> <b>Assemble the aar file</b>. To assemble the aar file using the 
  command line, first set environment variable ANDROID_HOME to the SDK
  directory, then run the gradle "assembleRelease" target from within the
  "sqlite3" sub-directory of the project directory. For example:
<verbatim>
    $ export ANDROID_HOME=~/Android/Sdk/
    $ cd sqlite3
    $ ../gradlew assembleRelease</verbatim>
  <p>
  Assembling an aar file using Android Studio is similar. Open the SQLite
  Android bindings project using Android Studio, run a "gradle sync", then
  run the "assembleRelease" gradle task within the "sqlite3" module.
  <p>
  Using either the command line or Android Studio to run the gradle task
  causes the aar file to be created at:
  <code>sqlite3/build/outputs/aar/sqlite3-release.aar</code>.
  <p>
  Once the custom aar file has been created, it may be used in an Android
  Studio application as described above. The aar file should be roughly
  4.5MB in size. If it is much smaller than this (closer to 100KB), this
  indicates that the aar file is missing the native libraries. The usual
  cause of this is an unnoticed error while building the native libraries 
  (step 2 above).
  <p>
  If the <code>Android.mk</code> file described in step 2 above is edited 
  after a build has been run, it may be necessary to run the 
  gradle "clean" target (either with <code>../gradlew clean</code> or through
  Android Studio) before rebuilding the aar file to ensure a correct build.
</ol>








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|


















|
|
|
<







121
122
123
124
125
126
127



















128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
    -DSQLITE_ENABLE_JSON1
    -DSQLITE_ENABLE_FTS3</verbatim>
  To build the SQLite library with some other combination of command line
  switches, edit the <code>Android.mk</code> file at this location:
<verbatim>
    sqlite3/src/main/jni/sqlite/Android.mk</verbatim>




















  <li> <b>Build and Assemble the aar file</b>. To assemble the aar file using the 
  command line, first set environment variable ANDROID_HOME to the SDK
  directory, then run the gradle "assembleRelease" target from within the
  "sqlite3" sub-directory of the project directory. For example:
<verbatim>
    $ export ANDROID_HOME=~/Android/Sdk/
    $ cd sqlite3
    $ ../gradlew assembleRelease</verbatim>
  <p>
  Assembling an aar file using Android Studio is similar. Open the SQLite
  Android bindings project using Android Studio, run a "gradle sync", then
  run the "assembleRelease" gradle task within the "sqlite3" module.
  <p>
  Using either the command line or Android Studio to run the gradle task
  causes the aar file to be created at:
  <code>sqlite3/build/outputs/aar/sqlite3-release.aar</code>.
  <p>
  Once the custom aar file has been created, it may be used in an Android
  Studio application as described above. The aar file should be roughly
  3.2MB in size. If it is much smaller than this (closer to 100KB), this
  indicates that the aar file is missing the native libraries for one
  reason or another. Consult the build logs.

  <p>
  If the <code>Android.mk</code> file described in step 2 above is edited 
  after a build has been run, it may be necessary to run the 
  gradle "clean" target (either with <code>../gradlew clean</code> or through
  Android Studio) before rebuilding the aar file to ensure a correct build.
</ol>