Using Chilkat in an Android Studio Project
A step-by-step guide to adding the Chilkat Java library to an Android Studio app: copy the native libraries and Java sources into the project, grant INTERNET permission, load the library, and call Chilkat.
First, download the Chilkat Android Java
library (chilkat-android.zip) and unzip it.
What the download contains
chilkat-android/ ├─ libs/ native JNI libraries, one folder per ABI │ ├─ arm64-v8a/ libchilkat.so │ ├─ armeabi-v7a/ libchilkat.so │ ├─ x86/ libchilkat.so │ └─ x86_64/ libchilkat.so └─ src/com/chilkatsoft/ Chilkat Java class sources (Ck*.java)
You'll copy the libs/ contents and the com/chilkatsoft sources
into your Android Studio project, as shown next.
Add Chilkat to your project
-
Copy the native libraries to jniLibs
Copy each ABI folder from the download's
libs/into app/src/main/jniLibs/ (create thejniLibsfolder if it doesn't exist), keeping the ABI folder names.More detail: Where to put the Chilkat JNI shared libraries.
-
Copy the Chilkat Java sources
Copy the download's
src/com/chilkatsoftfolder into your app's Java source root so the package path becomes app/src/main/java/com/chilkatsoft/.More detail: Copy Chilkat Java sources into your project.
-
Grant INTERNET permission
Add this to your
AndroidManifest.xml(required for any Chilkat feature that uses the network):<uses-permission android:name="android.permission.INTERNET" /> -
Load the native library, then use Chilkat
Load
libchilkatonce (astaticblock runs when the class is loaded), import the Chilkat classes, and call them. The Chilkat-related lines are highlighted:package com.test; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import com.chilkatsoft.*; public class SimpleActivity extends Activity { static { System.loadLibrary("chilkat"); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); // Unlock Chilkat once (any string starts the 30-day trial; // use your purchased code after licensing). CkGlobal glob = new CkGlobal(); glob.UnlockBundle("Anything for 30-day trial"); CkCrypt2 crypt = new CkCrypt2(); tv.setText(crypt.version()); setContentView(tv); } }
Where everything ends up in the project
YourApp/app/src/main/ ├─ java/com/chilkatsoft/ ← Chilkat Java sources (Step 2) │ ├─ chilkat.java │ ├─ chilkatJNI.java │ └─ Ck*.java ├─ jniLibs/ ← native libraries (Step 1) │ ├─ arm64-v8a/ libchilkat.so │ ├─ armeabi-v7a/ libchilkat.so │ ├─ x86/ libchilkat.so │ └─ x86_64/ libchilkat.so └─ AndroidManifest.xml ← INTERNET permission (Step 3)
Tips & common errors
UnsatisfiedLinkError loading the library
Make sure System.loadLibrary("chilkat") runs before any Chilkat class is
used, and that jniLibs contains the .so for the device's ABI
(include arm64-v8a for real devices).
Network calls fail
Confirm the INTERNET permission (Step 3) is in the manifest.
Unresolved com.chilkatsoft classes
The Chilkat sources must sit under a com/chilkatsoft/ folder on the Java
source path (Step 2).