Imported module in Android Studio can't find i

2019-03-14 07:55发布

问题:

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.

回答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.



回答2:

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



回答3:

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')


回答4:

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



回答5:

In my case, I did add in app gradle:

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.



回答6:

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.