Imported module in Android Studio can't find imported class
Solution 1
First of all, you must import your library project by following that path:
File --> New --> Import Module
After you have imported the library project successfully, you must check your build.gradle file inside your project's folder if the following line is present at the "dependencies" section:
implementation project(':NameOfTheLibProject')
Then your project must be built successfully.
Solution 2
I had the same problem. I just did: Invalidate / Restart ..
Solution 3
I found that my issue was the Android Plugin Version under Project Structure --> Project was different to the version my plugins all used. Once I aligned them to the same version, I could see all my classes from my imported module.
Took me hours :(
Solution 4
I too had trouble importing module as it was not appearing in list of modules. And way it worked for me is manually entering it in settings.gradle this way:
include ':app', 'module_name'
And in build.gradle
compile project(':module_name')
Solution 5
In my case, I did add in app
gradle:
// Nearly deprecated.
compile project(':NameOfTheLibProject')
// Or
implementation project(':NameOfTheLibProject')
but it only works when I change
compileSdkVersion
minSdkVersion
targetSdkVersion
in app
and the other modules are the same.
user1971
Updated on July 09, 2022Comments
-
user1971 almost 2 years
I recently downloaded the ViewPagerIndicator library and imported it into android studio. After adding it to my project I get a rendering error "The following classes could not be found:" and points to com.viewpagerindicator.IconPageIndicator.
The steps I took were
Files->Import Module->'library name'
,Project Structure -> Dependencies -> + the imported module
. Then to my layout xml file I added the<com.viewpagerindicator.IconPageIndicator />
, after that I got the missing class problem.It compiles just fine and I went through all of the build.gradle and settings.gradle files and compared them to what they should be online.
MyApp->build.gradle
hascompile project(':library')
underdependencies
settings.gradle
hasinclude ':library'
with no build errors. -
Quintin Balsdon over 8 yearsYou need to check that the Android Plugin Version is the same for both the Project and the imported module.
-
Vadiraj Purohit about 8 years+1 to your answer This looks to be a limitation on the android modules. What if we want to use main project with gradle plugin
com.android.tools.build:gradle:2.1.0
and library module withcom.android.tools.build:gradle-experimental:0.7.0
? Library module's classes are not visible to main project in this case :-( -
Lakedaemon almost 7 yearsThis saved my day too : my main project (android-gradle-plugin 2.4.0-alpha7') was reusing an external module (from another project whose android-gradle-plugin was 2.3.3). By aligning all plugins, some code (visible in the ide but invisible fro gradle) suddenly became visible for gradle.
-
Dan about 6 yearsThis sounds like the issue I'm having but when I go to "Project Structure > Project" the "Android Plugin Version" field is blank. Only the "Gradle Version" is populated. If I type something in that field it seems to get reset. Any ideas? This is driving me up the wall.
-
xarlymg89 about 6 yearsI had a very similar issue. My library was added fine and I could see the classes were reachable from my project. However, if a new class was created in the library, even a rebuild / clean + build didn't make the new classes available. I changed the minSdkVersion from my library build.gradle and voilà (just because I remembered I recently updated the one from my project)!
-
Nguyen Tan Dat about 6 yearsGlad that it helps you. Cheer!
-
xarlymg89 about 6 yearsAlthough this works, I know we should be missing something. Shouldn't be that difficult to effectively recompile an Android Library. Either that, or there's an annoying bug.
-
Bheid about 6 yearsalso check settings.gradle and include library like:
include ':app', ':mylib'
-
Yawar over 5 yearsstuck at this for almost an hour. And this solved my issue. Logged in to
so
just to upvote this. -
Admin over 5 years
compile
is now deprecated. useimplementation
orapi
instead. -
varun about 5 yearsFurther, for your understanding, notice how the
build.gradle
file of your newly imported module has a line at the top that readsapply plugin: 'com.android.library'
, whereas your app'sbuild.gradle
file has the lineapply plugin 'com.android.application'
. Just a surface level insight as to what the IDE thanklessly does for your convenience!!! :P