Tencent / wcdb
- суббота, 10 июня 2017 г. в 03:11:39
C
Multi-platform database framework from WeChat application
中文版本请参看这里
WCDB is an efficient, complete, easy-to-use mobile database framework used in WeChat application. It's currently available on iOS, macOS and Android.
github "Tencent/WCDB"
to your Cartfile;carthage update
.WCDB.framework
from the appropriate platform directory in Carthage/Build/
to the Linked Binary and Libraries
section of your Xcode project’s Build Phases
settings;Build Phases
settings tab, click the "+" icon and choose New Run Script Phase
. Create a Run Script with carthage copy-frameworks
and add the paths to the frameworks under "Input Files": $(SRCROOT)/Carthage/Build/iOS/WCDB.framework
;git submodule update --init --recursive
.WCDB.xcodeproj
in wcdb/apple/
into your project;WCDB.framework
to the Target Dependencies
section and Linked Binary and Libraries
of your Xcode project's `Build Phases" settings;WCDB.framework
to the "Enbedded Binaries" section of your Xcode project's "General" settings;Add #import <WCDB/WCDB.h>
at the top of your Objective-C++ source files and start your WCDB journey.
Tutorials can be found here.
To include WCDB to your project, choose either way: import via Maven or via AAR package.
To import WCDB via Maven repositories, add the following lines to build.gradle
on your
app module:
dependencies {
compile 'com.tencent.wcdb:wcdb-android:1.0.0'
// Replace "1.0.0" to any available version.
}
This will cause Gradle to download AAR package from jcenter while building your application.
1. Download AAR package from release page.
2. Import the AAR as new module. In Android Studio, select File -> New -> New Module...
menu and choose "Import JAR/AAR Package"
.
3. Add a dependency on the new module. This can be done using File -> Project Structure...
in Android Studio, or by adding following code to application's build.gradle
:
dependencies {
// Change "wcdb" to the actual module name specified in step 2.
compile project(':wcdb')
}
WCDB has interfaces very similar to Android SQLite Database APIs. To migrate you application from
AOSP API, change import path from android.database.*
to com.tencent.wcdb.*
, and
android.database.sqlite.*
to com.tencent.wcdb.database.*
. After import path update,
your application links to WCDB instead of AOSP API.
To open or create an encrypted database, use with-password versions of
SQLiteDatabase.openOrCreateDatabase()
, SQLiteOpenHelper.getWritableDatabase()
,
or Context.openOrCreateDatabase()
.
Note: WCDB uses byte[]
for password instead of String
in SQLCipher Android Binding.
String password = "MyPassword";
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase("/path/to/database", password.getBytes(),
null, null);
See sample-encryptdb
for sample for transferring data between plain-text and encrypted
databases.
See sample-repairdb
for instructions how to recover corrupted databases using RepairKit
.
By default, WCDB prints its log message to system logcat. You may want to change this
behavior in order to, for example, save logs for troubleshooting. WCDB can redirect
all of its log outputs to user-defined routine using Log.setLogger(LogCallback)
method.
WCDB itself can be built apart from its dependencies using Gradle or Android Studio.
To build WCDB Android library, run Gradle on android
directory:
$ cd android
$ ./gradlew build
Building WCDB requires Android NDK installed. If Gradle failed to find your SDK and/or
NDK, you may need to create a file named local.properties
on the android
directory
with content:
sdk.dir=path/to/sdk
ndk.dir=path/to/ndk
Android Studio will do this for you when the project is imported.
WCDB depends on OpenSSL crypto library and SQLCipher. You can rebuild all dependencies if you wish. In this case, a working C compiler on the host system, Perl 5, Tcl and a bash environment is needed to be installed on your system.
To build dependencies, checkout all submodules, set ANDROID_NDK_ROOT
environment
variable to your NDK path, then run build-depends-android.sh
:
$ export ANDROID_NDK_ROOT=/path/to/ndk
$ ./build-depends-android.sh
This will build OpenSSL crypto library and generate SQLCipher amalgamation sources and place them to proper locations suitable for WCDB library building.