user1971
user1971

Reputation: 698

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.

Upvotes: 43

Views: 61308

Answers (9)

Paul
Paul

Reputation: 1645

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

Upvotes: 0

Kumar Santanu
Kumar Santanu

Reputation: 701

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

}

Upvotes: 0

Ali Nawaz
Ali Nawaz

Reputation: 2500

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.

Upvotes: 0

Dastin
Dastin

Reputation: 4507

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.

Upvotes: 5

Bahadir Tasdemir
Bahadir Tasdemir

Reputation: 10783

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.

Upvotes: 56

johnnicholai
johnnicholai

Reputation: 129

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

Upvotes: 12

Safeer
Safeer

Reputation: 1467

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

Upvotes: 6

rajesh v
rajesh v

Reputation: 521

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.

Upvotes: 1

Quintin B
Quintin B

Reputation: 5881

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

Upvotes: 13

Related Questions