Copy Chilkat Java Sources into your Android Project Directory
In an Android project, Chilkat Java source files should be placed in the correct location to ensure they are properly recognized by the project and included in the build process. Here's where they should go:
1. "src/main/java" Directory
The standard location for Java source files in an Android project is:
app/src/main/java/<package-name>
The "<package-name>" folder structure should match the package declaration in the Chilkat Java source files. For example:
Example:
If the Chilkat source files have the package declaration:
package com.chilkatsoft;
Place the files in:
app/src/main/java/com/chilkatsoft/
2. Steps to Add Chilkat Java Files
- Create the Directory Structure:
- Navigate to "app/src/main/java/" in your project directory.
- Create the package directory matching the Chilkat package, e.g., "com/chilkatsoft/".
- Copy the Files:
- Copy the Chilkat ".java" source files (e.g., "CkHttp.java", "CkJsonObject.java") into the "com/chilkatsoft/" directory.
- Sync with Android Studio:
- Open Android Studio.
- Right-click the "java" folder and select Synchronize to ensure the IDE recognizes the new files.
3. Add Dependencies (if needed)
- Chilkat also requires its native ".so" library for JNI functionality.
- Place the ".so" files in the appropriate directories under:
app/src/main/jniLibs/<ABI>/
For example:
app/src/main/jniLibs/armeabi-v7a/libchilkat.so app/src/main/jniLibs/arm64-v8a/libchilkat.so
4. Verify Build Configuration
Ensure the Java and native libraries are included in the build process:
- Gradle Build File ("build.gradle"):
- No special configuration is typically needed for Java source files in "src/main/java".
- If using ".so" files, ensure the "jniLibs" folder is packaged:
android { ... sourceSets { main { jniLibs.srcDirs = ['src/main/jniLibs'] } } }
5. Import and Use Chilkat Classes
After placing the files in the correct directory, you can use them in your code:
import com.chilkatsoft.CkHttp; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CkHttp http = new CkHttp(); // Use Chilkat methods here } }
Summary
- Place Chilkat ".java" files in "app/src/main/java/com/chilkatsoft/".
- Place required ".so" files in "app/src/main/jniLibs/<ABI>/".
- Synchronize the project in Android Studio and ensure the Gradle build file includes native libraries if applicable.