43

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 has compile project(':library') under dependencies settings.gradle has include ':library' with no build errors.

user1971
  • 698
  • 2
  • 6
  • 18
  • I am unable to reproduce this issue. This is what I have in my layout XML: ` – Eugene Aug 25 '14 at 16:28
  • What would the path to the class look like on your project. – user1971 Aug 25 '14 at 17:05
  • Are you asking about location of the .java file? It's in ${project}/library/src/main/java/com/viewpagerindicator/IconPageIndicator.java – Eugene Aug 25 '14 at 17:36
  • 1
    Is your application module that is using this class have `compile project(':library')` in dependencies in the `build.gradle`. I read that you used UI to add module dependency, but just want to make sure. – Eugene Aug 25 '14 at 17:37
  • Away from computer for a while; I will probably be back to it this weekend, but it most likely is. I did use the UI for the import. – user1971 Aug 25 '14 at 22:30

9 Answers9

56

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.

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
  • 10
    also check settings.gradle and include library like: `include ':app', ':mylib'` – Bheid Apr 11 '18 at 09:47
  • 4
    `compile` is now deprecated. use `implementation` or `api` instead. –  Nov 20 '18 at 18:26
  • Further, for your understanding, notice how the `build.gradle` file of your newly imported module has a line at the top that reads `apply plugin: 'com.android.library'`, whereas your app's `build.gradle` file has the line `apply plugin 'com.android.application'`. Just a surface level insight as to what the IDE thanklessly does for your convenience!!! :P – varun Apr 27 '19 at 12:56
13

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 :(

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
  • You need to check that the Android Plugin Version is the same for both the Project and the imported module. – Quintin Balsdon Dec 16 '15 at 19:57
  • 3
    +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 with ```com.android.tools.build:gradle-experimental:0.7.0```? Library module's classes are not visible to main project in this case :-( – Vadiraj Purohit May 19 '16 at 21:04
  • This 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. – Lakedaemon Jul 20 '17 at 11:56
  • This 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. – Dan Apr 09 '18 at 21:23
12

I had the same problem. I just did: Invalidate / Restart ..

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
johnnicholai
  • 129
  • 1
  • 2
  • stuck at this for almost an hour. And this solved my issue. Logged in to `so` just to upvote this. – Yawar Sep 16 '18 at 09:02
6

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')
Safeer
  • 1,407
  • 1
  • 25
  • 29
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.

Nguyen Tan Dat
  • 3,780
  • 1
  • 23
  • 24
  • I 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)! – xarlymg89 Apr 10 '18 at 10:37
  • Glad that it helps you. Cheer! – Nguyen Tan Dat Apr 11 '18 at 07:55
  • 1
    Although 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. – xarlymg89 Apr 11 '18 at 09:44
1

The following solution worked for me,just two steps.

Go to your project structure on android studio, select project from left side.Change Android plugin version to Gradle version press ok.

If error occurs after synchronization again go to project structure and select project.undo the android plugin version like before.Gradle will align the library and make the class visible to XML files.

rajesh v
  • 521
  • 4
  • 4
0

The issue in my case was different compile and target SDK version, mentioned in my main app module and your added lib module. Once I matched both of them it worked perfectly. So just open build.gradle file of app-level and lib module-level check for the SDK version.

Ali Nawaz
  • 2,016
  • 20
  • 30
0

settings.gradle

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(':wheel') // "Wheel" - you're project path name

}
Kumar Santanu
  • 603
  • 1
  • 7
  • 14
0

In case you just changed the name of your project in the pubspec.yaml File, make sure to change the import names as well, because they will stay the same and therefore wont find the new named directory.

Ex. change this to :

import 'package:previousName/backend/connector/userConnector.dart';

to this:

 import 'package:newName/backend/connector/userConnector.dart';

As far as i know, there is no terminal command for that, only find-in-files-replace :(

Paul
  • 1,349
  • 1
  • 14
  • 26