Saturday, 5 February 2022

How to import other modules defined in the same Android app project inside Kotlin code?

I was trying to understand how to create multiple independent modules inside a project and use them in the main app module. I am using android studio Arctic Fox 2020.3.1. I have difficulty in importing the module into Kotlin code. Here is the step I followed.

I have created a 'basic activity' project named MyAppProj. It created a project with module app inside it. (build+run works fine)

Next I added a new module to the project MyAppProj. Since I needed to call C++, I created a 'Android native library' module. As per the suggestion from Android Studio, I used MyAppProj:nativelib as the module name. I didn't know what that ":" was for. (build+run works fine)

Now I have the following structure:

Project Structure

Question: What should I do to use the NativeLib class (defined inside MyAppProj:nativelib module) inside the app module's MainActivity.kt file?

All the paths that I tried so far have failed, such as:

import com.myhomeorg.myappproj.nativelib
import nativelib

Note: I am a beginner in Android development. Your help will be greatly appreciated!



from How to import other modules defined in the same Android app project inside Kotlin code?

No comments:

Post a Comment