이 답변의 차이를 설명 할 것이다 implementation, api그리고 compile프로젝트에.
세 개의 Gradle 모듈이있는 프로젝트가 있다고 가정 해 보겠습니다.
- 앱 (Android 애플리케이션)
- myandroidlibrary (Android 라이브러리)
- myjavalibrary (Java 라이브러리)
app이 myandroidlibrary종속한다. myandroidlibrary이 myjavalibrary 종속한다.

myjavalibrary이 MySecret클래스를
public class MySecret {
public static String getSecret() {
return "Money";
}
}
myandroidlibrary보유 MyAndroidComponent로부터 값을 조작 클래스 MySecret클래스.
public class MyAndroidComponent {
private static String component = MySecret.getSecret();
public static String getComponent() {
return "My component: " + component;
}
}
마지막으로, app의 가치에만 관심이 있습니다myandroidlibrary
TextView tvHelloWorld = findViewById(R.id.tv_hello_world);
tvHelloWorld.setText(MyAndroidComponent.getComponent());
이제 의존성에 대해 이야기 해 봅시다 ...
app:myandroidlibrary그래서 appbuild.gradle 사용 에서 소비해야합니다 implementation.
( 참고 : API / 컴파일도 사용할 수 있습니다. 그러나 잠시 동안 그 생각을 유지하십시오.)
dependencies {
implementation project(':myandroidlibrary')
}

myandroidlibrarybuild.gradle은 어떻게 생겼을까 요? 어떤 범위를 사용해야합니까?
우리는 세 가지 옵션이 있습니다 :
dependencies {
// Option #1
implementation project(':myjavalibrary')
// Option #2
compile project(':myjavalibrary')
// Option #3
api project(':myjavalibrary')
}

그들 사이의 차이점은 무엇이며 어떻게 사용해야합니까?
컴파일 또는 API (옵션 # 2 또는 # 3)

당신이 사용하는 경우 compile나 api. Android 애플리케이션은 이제 클래스 인 myandroidcomponent종속성 에 액세스 할 수 있습니다 MySecret.
TextView textView = findViewById(R.id.text_view);
textView.setText(MyAndroidComponent.getComponent());
// You can access MySecret
textView.setText(MySecret.getSecret());
구현 (옵션 # 1)

implementation구성을 사용하는 경우 MySecret노출되지 않습니다.
TextView textView = findViewById(R.id.text_view);
textView.setText(MyAndroidComponent.getComponent());
// You can NOT access MySecret
textView.setText(MySecret.getSecret()); // Won't even compile
어떤 구성을 선택해야합니까? 그것은 실제로 귀하의 요구 사항에 달려 있습니다.
당신이 경우 종속성 노출 할 사용 api하거나 compile.
당신이 경우 종속성을 노출하지 않으려는 (내부 모듈 숨어을)를 사용합니다 implementation.
노트 :
이것은 Gradle 구성의 요지 일뿐입니다 ( 표 49.1 참조) . Java 라이브러리 플러그인- 자세한 설명을 위해 종속성을 선언하는 데 사용되는 구성
이 답변의 샘플 프로젝트는 https://github.com/aldoKelvianto/ImplementationVsCompile에서 제공됩니다.