Hanbit the Developer

[build.gradle] I can't found libraries/modules after implements 본문

Mobile/Android

[build.gradle] I can't found libraries/modules after implements

hanbikan 2021. 3. 5. 17:07

build.gradle에서 implements로 원하는 모듈을 추가하여도 import가 되지 않는 문제이다.

해결 방법은 다음과 같다.

1. (/app/build.gradle이 아니라) /build.gradle에 다음과 같은 내용을 추가한다.

allprojects {
    repositories {
        google()
        jcenter()
    }
}

참고로 전체 내용은 다음과 같다.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.4.31'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

2. 이렇게 하였음에도 불구하고 External Libraries에 추가되지 않는 경우가 있다. 이 경우는 간단하다.

'Sync Project with Gradle Files'을 누르면 된다.