1
2
3
4
5
6
7
8
android {
    ...
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = file(output.outputFile.getPath().replace('/app-', "/${apkName}-"))
        }
    }
}

그래들(Gradle) 3.0.0 부터 ‘output.outputFile’은 read-only 속성이기 때문에 아래와 같이 씽크(sync) 에러가 납니다. 여기를 참고하세요.

1
2
Gradle sync failed: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
Consult IDE log for more details (Help | Show Log) (746ms)

아래처럼 outputFileName으로 수정하세요.

1
2
3
4
5
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFileName = output.outputFile.getPath().replace('/app-', "/${apkName}-")
    }
}

추가로 NDK 빌드에서 아래 에러가 나거나 C++을 사용하려면 아래 코드를 추가하세요.

1
2
3
4
5
6
Error:Execution failed for task ':app:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
  Consider using CMake or ndk-build integration. For more information, go to:
   https://d.android.com/r/studio-ui/add-native-code.html
  Alternatively, you can use the experimental plugin:
   https://developer.android.com/r/tools/experimental-plugin.html
1
2
3
4
5
6
7
8
android {
    ...
    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }
}