Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including kotlin file into App_Resources/Android/src/main/java seems to not work #1682

Closed
darkyelox opened this issue Oct 8, 2021 · 8 comments

Comments

@darkyelox
Copy link

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 8.1.1
  • Cross-platform modules: 8.1.1
  • Android Runtime: 8.1.1

Describe the bug
I'm trying to use a Kotlin file with some function for include into my Angular project but everything about it is undefined, for example if I define my packages as org.acrapp then acrapp is undefined and so on.

But if I create a Test.java file with a class inside and package org.acrapp the package isn't undefined anymore but everything from the Kotlin file is undefined (no classes no functions, etc)

To Reproduce
This is what I'm trying to do:

// Tools.kt on App_Resources/Android/src/main/java folder
@file:JvmName("Tools")

package org.acrapp

class TestKotlin

fun sayHello() {
    print("Hello World!")
}
// In some TypeScript Angular component
constructor(
  private readonly http: HttpClient,
  private readonly feedback: FeedbackService,
) {
  console.log(org.acrapp) // this prints undefined if package is defined in a Kotlin file, but if defined in Java file it isn't undefined
}

I noticed that if the Kotlin file has an syntax error the CLI stars an Android build but no error is thrown, is like it is ignoring my Kotlin file (Java files are compiled as expected)

Expected behavior
I was expecting that Kotlin was enabled by default for use in App_resources, if that isn't the case have I do enable it? how?

Additional context
Running on Genymotion with Android 10

@triniwiz
Copy link
Member

triniwiz commented Oct 9, 2021

Can u try adding the following to the app.gradle

project.ext {
    useKotlin = "true"
}

@darkyelox
Copy link
Author

darkyelox commented Oct 11, 2021

Can u try adding the following to the app.gradle

project.ext {
    useKotlin = "true"
}

Tried that and also in before-plugins.gradle but nothing works, the file is ignored even if it has syntax errors when built. Do you have an example of a working project using kotlin that way? (without using a plugin but using kotlin file directly in App_Resources/Android...)

@farfromrefug
Copy link
Contributor

@darkyelox

project.ext {
    useKotlin = "true"
}

should be the way. Did you clean after adding it?

@darkyelox
Copy link
Author

@darkyelox

project.ext {
    useKotlin = "true"
}

should be the way. Did you clean after adding it?

Did it and nothing changed, here is my graddle, it compiles but ignores Kotlin files (even with syntax error).

// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
dependencies {
  implementation 'com.android.support:multidex:1.0.3'
  implementation 'com.squareup.okhttp3:okhttp:4.9.0'
}

// If you want to add something to be applied before applying plugins' include.gradle files
// e.g. project.ext.googlePlayServicesVersion = "15.0.1"
// create a file named before-plugins.gradle in the current directory and place it there

android {
  defaultConfig {
    minSdkVersion 19
    generatedDensities = []
    multiDexEnabled true
  }

  packagingOptions {
      pickFirst '**/*.so'
  }

  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

project.ext {
  useKotlin = "true"
}

@triniwiz
Copy link
Member

@darkyelox you will need to create a gradle.properties file in App_Resources/Android then add the following

useKotlin=true

@farfromrefug
Copy link
Contributor

@triniwiz I actually don't think the gradle.properties gets picked up in App_Resources. I had to make a hook to merge the platform one with the one I would put in App_Resources

@shirakaba
Copy link

@darkyelox you will need to create a gradle.properties file in App_Resources/Android then add the following

useKotlin=true

Confirmed that this worked (for someone else) on Discord!

@farfromrefug
Copy link
Contributor

@shirakaba awesome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants