Adrian Ivasku
Adrian Ivasku

Reputation: 1118

Android studio inherit class from external module

I have an android studio project with several external modules (modules are located on different file paths) and I can`t manage to make the Android Studio see the abstract class from a module.

Some of the modules depends on other modules, eg: ModuleA is a dependency for ModuleB and ModuleB is a dependency to my main app module. The ModuleB can see the abstract class from ModuleA but my main app module cannot see the abstract class from ModuleB.

In my main app module I have a class projectHelper that extends abstract class from ModuleB. eg:

public class projectHelper extends Helper {

}

And whatever I tried I cannot make the main module app to see the abstract Helper class from ModuleB module.

Gradle sync passes ok but the Studio reports that the Helper class cannot be resolved.

I have tried to include the package from the ModuleB, even extend the class something like "extends com.android.ModuleB.Helper" but the class nor the package cannot be resolved.

I am using Android Studio 1.5.1 and Android NDK with com.android.tools.build:gradle-experimental:0.4.0 plugin.

I have done this in Eclipse and it works without a problem.

It also offers me to move the class from ModuleB to my main App module (but I cannot do that), see image: (I had to obscure the package names). module

Upvotes: 2

Views: 1351

Answers (1)

Adrian Ivasku
Adrian Ivasku

Reputation: 1118

For now, this can`t be done with experimental NDK plugin.

I have solved this with android.productFlavors. The point is to make the code beside your main dir in separate dir, like flavour1, give it java->packageName>someClass.java. It must have the same package name as the main app, but ignore that because you can change it in gradle at that specific build flavour

create("googleFree") {
        applicationId = "com.example.mySpecialPackage"
    }

and that package name will be replaced in the manifest when the APK is built.

I have learned this from this link http://blog.robustastudio.com/mobile-development/android/building-multiple-editions-of-android-app-gradle/

Upvotes: 1

Related Questions