Android Studio 中的导入模块找不到导入的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25477052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:27:43  来源:igfitidea点击:

Imported module in Android Studio can't find imported class

androidandroid-studioandroid-library

提问by user1971

I recently downloaded the ViewPagerIndicator libraryand 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.

我最近下载了ViewPagerIndicator 库并将其导入 android studio。将其添加到我的项目后,出现渲染错误“找不到以下类:”并指向 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.

我采取的步骤是Files->Import Module->'library name'Project Structure -> Dependencies -> + the imported module。然后在我的布局 xml 文件中添加了<com.viewpagerindicator.IconPageIndicator />,之后我遇到了丢失的类问题。

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.

它编译得很好,我浏览了所有 build.gradle 和 settings.gradle 文件,并将它们与应该在线的内容进行了比较。

MyApp->build.gradlehas compile project(':library')under dependenciessettings.gradlehas include ':library'with no build errors.

MyApp->build.gradlehas compile project(':library')under dependenciessettings.gradlehasinclude ':library'没有构建错误。

回答by Bahadir Tasdemir

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:

成功导入库项目后,如果“依赖项”部分出现以下行,则必须检查项目文件夹中的 build.gradle 文件:

implementation project(':NameOfTheLibProject')

Then your project must be built successfully.

那么你的项目必须成功构建。

回答by Quintin Balsdon

I found that my issue was the Android Plugin Versionunder Project Structure--> Projectwas 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.

我发现我的问题是项目结构下的Android 插件版本-->项目与我所有插件使用的版本不同。一旦我将它们与相同的版本对齐,我就可以从导入的模块中看到我的所有类。

Took me hours :(

花了我几个小时:(

回答by johnnicholai

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

我有同样的问题。我刚刚做了:无效/重新启动..

回答by Safeer

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.gradlethis way:

我也无法导入模块,因为它没有出现在模块列表中。它对我有用的方式是在settings.gradle 中手动输入它:

include ':app', 'module_name'

And in build.gradle

build.gradle 中

compile project(':module_name')

回答by Nguyen Tan Dat

In my case, I did add in appgradle:

就我而言,我确实在appgradle 中添加了:

// Nearly deprecated.
compile project(':NameOfTheLibProject')
// Or
implementation project(':NameOfTheLibProject')

but it only works when I change

但它只在我改变时有效

compileSdkVersion 
minSdkVersion 
targetSdkVersion 

in appand the other modules are the same.

inapp和其他模块是一样的。

回答by rajesh v

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.

转到您在 android studio 上的项目结构,从左侧选择项目。将 Android 插件版本更改为 Gradle 版本按确定。

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.

如果再次同步后出现错误,请转到项目结构并选择项目。撤消之前的 android 插件版本。Gradle 将对齐库并使该类对 XML 文件可见。