Android - Kotlin files are present in apk after compilation












1















I have an android project with both java and kotlin files.



After compilation, when I unzip the generated apk file, I can see all the Kotlin files of my project in their package path.
The Java files however are not present.



How can I fix this, and stop the Koltin files from beeing added to the apk ?



Thanks



Screenshot of unzipped apk content



My build.gradle:




buildscript {
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'

repositories {
maven { url "https://jitpack.io" }
mavenCentral()
jcenter()
flatDir{
dirs 'libs'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
/* A bunch of dependencies */
}

android {

compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {

minSdkVersion 19
targetSdkVersion 27

multiDexEnabled true

setOutputPath applicationVariants, goevent["outputDir"], goevent["outputName"]
setOutputPath testVariants, goevent["outputDir"], goevent["outputNameTest"]
}

dataBinding {
enabled = true
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'main/AndroidManifest.xml'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.properties'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.xml'
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}

androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}

signingConfigs {
release {

//Fetch the signing file
File signFile = rootProject.file('signing.properties')

//Read the signing properties file
Properties properties = new Properties()
properties.load(new FileInputStream(signFile))


if (properties['signingKeystorePath'] && properties['signingKeystorePassword'] && properties['signingKeyAlias'] && properties['signingKeyPassword']) {
String toolsPath = System.getenv("TOOLS")
if(toolsPath != null) {
storeFile file(toolsPath + properties['signingKeystorePath'])
storePassword properties['signingKeystorePassword']
keyAlias properties['signingKeyAlias']
keyPassword properties['signingKeyPassword']
}

} else {

//If the signing file doesn't exist or the properties are not set
if (project.hasProperty("signingKeystorePath")) {
storeFile file("$signingKeystorePath")
storePassword signingKeystorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}

}
}
}
lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.pro'
signingConfig signingConfigs.release
zipAlignEnabled true
}
}

dexOptions {
jumboMode = true
}
}

def setOutputPath(variants, dir, name) {
variants.all { variant ->
variant.outputs.all { output ->
def relativeRootDir = output.packageApplication.outputDirectory.toPath()
.relativize(rootDir.toPath()).toFile()

output.outputFileName = new File("$relativeRootDir/$dir", name)
}
}
}









share|improve this question

























  • You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

    – p.alexey
    Nov 14 '18 at 21:50











  • Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

    – CommonsWare
    Nov 14 '18 at 22:40











  • @p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

    – Leguman
    Nov 15 '18 at 14:13













  • @CommonsWare I edited my question and added a screenshot of the unzipped apk output

    – Leguman
    Nov 15 '18 at 14:23











  • There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

    – CommonsWare
    Nov 15 '18 at 22:17
















1















I have an android project with both java and kotlin files.



After compilation, when I unzip the generated apk file, I can see all the Kotlin files of my project in their package path.
The Java files however are not present.



How can I fix this, and stop the Koltin files from beeing added to the apk ?



Thanks



Screenshot of unzipped apk content



My build.gradle:




buildscript {
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'

repositories {
maven { url "https://jitpack.io" }
mavenCentral()
jcenter()
flatDir{
dirs 'libs'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
/* A bunch of dependencies */
}

android {

compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {

minSdkVersion 19
targetSdkVersion 27

multiDexEnabled true

setOutputPath applicationVariants, goevent["outputDir"], goevent["outputName"]
setOutputPath testVariants, goevent["outputDir"], goevent["outputNameTest"]
}

dataBinding {
enabled = true
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'main/AndroidManifest.xml'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.properties'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.xml'
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}

androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}

signingConfigs {
release {

//Fetch the signing file
File signFile = rootProject.file('signing.properties')

//Read the signing properties file
Properties properties = new Properties()
properties.load(new FileInputStream(signFile))


if (properties['signingKeystorePath'] && properties['signingKeystorePassword'] && properties['signingKeyAlias'] && properties['signingKeyPassword']) {
String toolsPath = System.getenv("TOOLS")
if(toolsPath != null) {
storeFile file(toolsPath + properties['signingKeystorePath'])
storePassword properties['signingKeystorePassword']
keyAlias properties['signingKeyAlias']
keyPassword properties['signingKeyPassword']
}

} else {

//If the signing file doesn't exist or the properties are not set
if (project.hasProperty("signingKeystorePath")) {
storeFile file("$signingKeystorePath")
storePassword signingKeystorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}

}
}
}
lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.pro'
signingConfig signingConfigs.release
zipAlignEnabled true
}
}

dexOptions {
jumboMode = true
}
}

def setOutputPath(variants, dir, name) {
variants.all { variant ->
variant.outputs.all { output ->
def relativeRootDir = output.packageApplication.outputDirectory.toPath()
.relativize(rootDir.toPath()).toFile()

output.outputFileName = new File("$relativeRootDir/$dir", name)
}
}
}









share|improve this question

























  • You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

    – p.alexey
    Nov 14 '18 at 21:50











  • Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

    – CommonsWare
    Nov 14 '18 at 22:40











  • @p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

    – Leguman
    Nov 15 '18 at 14:13













  • @CommonsWare I edited my question and added a screenshot of the unzipped apk output

    – Leguman
    Nov 15 '18 at 14:23











  • There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

    – CommonsWare
    Nov 15 '18 at 22:17














1












1








1


2






I have an android project with both java and kotlin files.



After compilation, when I unzip the generated apk file, I can see all the Kotlin files of my project in their package path.
The Java files however are not present.



How can I fix this, and stop the Koltin files from beeing added to the apk ?



Thanks



Screenshot of unzipped apk content



My build.gradle:




buildscript {
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'

repositories {
maven { url "https://jitpack.io" }
mavenCentral()
jcenter()
flatDir{
dirs 'libs'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
/* A bunch of dependencies */
}

android {

compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {

minSdkVersion 19
targetSdkVersion 27

multiDexEnabled true

setOutputPath applicationVariants, goevent["outputDir"], goevent["outputName"]
setOutputPath testVariants, goevent["outputDir"], goevent["outputNameTest"]
}

dataBinding {
enabled = true
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'main/AndroidManifest.xml'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.properties'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.xml'
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}

androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}

signingConfigs {
release {

//Fetch the signing file
File signFile = rootProject.file('signing.properties')

//Read the signing properties file
Properties properties = new Properties()
properties.load(new FileInputStream(signFile))


if (properties['signingKeystorePath'] && properties['signingKeystorePassword'] && properties['signingKeyAlias'] && properties['signingKeyPassword']) {
String toolsPath = System.getenv("TOOLS")
if(toolsPath != null) {
storeFile file(toolsPath + properties['signingKeystorePath'])
storePassword properties['signingKeystorePassword']
keyAlias properties['signingKeyAlias']
keyPassword properties['signingKeyPassword']
}

} else {

//If the signing file doesn't exist or the properties are not set
if (project.hasProperty("signingKeystorePath")) {
storeFile file("$signingKeystorePath")
storePassword signingKeystorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}

}
}
}
lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.pro'
signingConfig signingConfigs.release
zipAlignEnabled true
}
}

dexOptions {
jumboMode = true
}
}

def setOutputPath(variants, dir, name) {
variants.all { variant ->
variant.outputs.all { output ->
def relativeRootDir = output.packageApplication.outputDirectory.toPath()
.relativize(rootDir.toPath()).toFile()

output.outputFileName = new File("$relativeRootDir/$dir", name)
}
}
}









share|improve this question
















I have an android project with both java and kotlin files.



After compilation, when I unzip the generated apk file, I can see all the Kotlin files of my project in their package path.
The Java files however are not present.



How can I fix this, and stop the Koltin files from beeing added to the apk ?



Thanks



Screenshot of unzipped apk content



My build.gradle:




buildscript {
ext.kotlin_version = '1.2.71'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'

repositories {
maven { url "https://jitpack.io" }
mavenCentral()
jcenter()
flatDir{
dirs 'libs'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
/* A bunch of dependencies */
}

android {

compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {

minSdkVersion 19
targetSdkVersion 27

multiDexEnabled true

setOutputPath applicationVariants, goevent["outputDir"], goevent["outputName"]
setOutputPath testVariants, goevent["outputDir"], goevent["outputNameTest"]
}

dataBinding {
enabled = true
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'main/AndroidManifest.xml'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.properties'
pickFirst 'META-INF/maven/com.squareup.okio/okio/pom.xml'
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}

androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}

signingConfigs {
release {

//Fetch the signing file
File signFile = rootProject.file('signing.properties')

//Read the signing properties file
Properties properties = new Properties()
properties.load(new FileInputStream(signFile))


if (properties['signingKeystorePath'] && properties['signingKeystorePassword'] && properties['signingKeyAlias'] && properties['signingKeyPassword']) {
String toolsPath = System.getenv("TOOLS")
if(toolsPath != null) {
storeFile file(toolsPath + properties['signingKeystorePath'])
storePassword properties['signingKeystorePassword']
keyAlias properties['signingKeyAlias']
keyPassword properties['signingKeyPassword']
}

} else {

//If the signing file doesn't exist or the properties are not set
if (project.hasProperty("signingKeystorePath")) {
storeFile file("$signingKeystorePath")
storePassword signingKeystorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}

}
}
}
lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.pro'
signingConfig signingConfigs.release
zipAlignEnabled true
}
}

dexOptions {
jumboMode = true
}
}

def setOutputPath(variants, dir, name) {
variants.all { variant ->
variant.outputs.all { output ->
def relativeRootDir = output.packageApplication.outputDirectory.toPath()
.relativize(rootDir.toPath()).toFile()

output.outputFileName = new File("$relativeRootDir/$dir", name)
}
}
}






android gradle kotlin android-proguard dex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 at 14:43









CuriousSuperhero

4,86231839




4,86231839










asked Nov 14 '18 at 21:43









LegumanLeguman

1,40411013




1,40411013













  • You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

    – p.alexey
    Nov 14 '18 at 21:50











  • Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

    – CommonsWare
    Nov 14 '18 at 22:40











  • @p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

    – Leguman
    Nov 15 '18 at 14:13













  • @CommonsWare I edited my question and added a screenshot of the unzipped apk output

    – Leguman
    Nov 15 '18 at 14:23











  • There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

    – CommonsWare
    Nov 15 '18 at 22:17



















  • You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

    – p.alexey
    Nov 14 '18 at 21:50











  • Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

    – CommonsWare
    Nov 14 '18 at 22:40











  • @p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

    – Leguman
    Nov 15 '18 at 14:13













  • @CommonsWare I edited my question and added a screenshot of the unzipped apk output

    – Leguman
    Nov 15 '18 at 14:23











  • There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

    – CommonsWare
    Nov 15 '18 at 22:17

















You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

– p.alexey
Nov 14 '18 at 21:50





You can use proguard for obfuscate your code. Just turn on it int build.gradle file: android {buildTypes {release { minifyEnabled true ...} } }.

– p.alexey
Nov 14 '18 at 21:50













Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

– CommonsWare
Nov 14 '18 at 22:40





Please explain in detail what "I can see all my Kotlin files" means. For example, you might want to show the output of the APK Analyzer or unzip or something that demonstrates what you are seeing.

– CommonsWare
Nov 14 '18 at 22:40













@p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

– Leguman
Nov 15 '18 at 14:13







@p.alexey Proguard seems to be turned on correctly, and I can see some warnings concerning Proguard while building the apk

– Leguman
Nov 15 '18 at 14:13















@CommonsWare I edited my question and added a screenshot of the unzipped apk output

– Leguman
Nov 15 '18 at 14:23





@CommonsWare I edited my question and added a screenshot of the unzipped apk output

– Leguman
Nov 15 '18 at 14:23













There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

– CommonsWare
Nov 15 '18 at 22:17





There's something fairly strange going on here. That's not normal. Did you make significant changes to your build.gradle file for this module?

– CommonsWare
Nov 15 '18 at 22:17












1 Answer
1






active

oldest

votes


















1














Finally found the issue:



I had to removed resources.srcDirs = ['src'] from the sources set



This was copying all non-java files contains under the src folder






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309163%2fandroid-kotlin-files-are-present-in-apk-after-compilation%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Finally found the issue:



    I had to removed resources.srcDirs = ['src'] from the sources set



    This was copying all non-java files contains under the src folder






    share|improve this answer




























      1














      Finally found the issue:



      I had to removed resources.srcDirs = ['src'] from the sources set



      This was copying all non-java files contains under the src folder






      share|improve this answer


























        1












        1








        1







        Finally found the issue:



        I had to removed resources.srcDirs = ['src'] from the sources set



        This was copying all non-java files contains under the src folder






        share|improve this answer













        Finally found the issue:



        I had to removed resources.srcDirs = ['src'] from the sources set



        This was copying all non-java files contains under the src folder







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 30 at 22:41









        LegumanLeguman

        1,40411013




        1,40411013
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309163%2fandroid-kotlin-files-are-present-in-apk-after-compilation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values