简体   繁体   中英

Imported module in Android Studio can't find imported class

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.

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.

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

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

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

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.

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.

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.

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

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM