Add SDK to Android Studio Project
How to add the .aar to an Android Studio project to build an app in Java to use the CONTXTFUL library.
The CONTXTFUL library
The CONTXTFUL plugin is provided as a .aar file. The .aar can be unzipped to expose the jni/
folder and a .jar
file
Copy the library
Unzip and copy the Contxtful directory (from the step above) under
[PATH]/[PROJECT NAME]/app/Contxtful
The resulting folder structure should look like this:
├── Contxtful
│ ├── classes.jar
│ └── jni
│ ├── arm64-v8a
│ │ ├── libContxtful_1.2.01.so
│ │ ├── libcurl.so
│ │ └── libsqlite.so
│ ├── armeabi-v7a
│ │ ├── libContxtful_1.2.01.so
│ │ ├── libcurl.so
│ │ └── libsqlite.so
│ ├── x86
│ │ ├── libContxtful_1.2.01.so
│ │ ├── libcurl.so
│ │ └── libsqlite.so
│ └── x86_64
│ ├── libContxtful_1.2.01.so
│ ├── libcurl.so
│ └── libsqlite.so |
Edit build.gradle
Edit build.gradle under the app/ folder and add the following block of lines like this:
defaultConfig {
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
arguments "-DANDROID_STL=c++_shared"
cFlags "-DHAVE_CONFIG_H -DBUILDING_LIBCURL"
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
// let gradle pack the shared library into apk
jniLibs.srcDirs = ['Contxtful/jni']
}
}
|
And also this under dependencies
, add:
implementation files('Contxtful/classes.jar')
implementation fileTree(include: ['*jar'], dir: 'libs') |
Still under the app/ folder, add the following lines to a file CMakeLists.txt
Edit AndroidManifest.xml
The .aar contains a AndroidManifest.xml. You need to add the permission from this manifest to your project’s manifest. This permission includes access to the wifi status to avoid wasting LTE and storage access to read and store logs.
Detailed information soon.
Link your project
Select Build→Refresh Linked c++ Projects
Use the Contxtful library
Instantiate the library
Stop the ContxtfulManager
Resume the ContxtfulManager
Setup Callback
Stop the callback
Destroy the ContxtfulManager