Android: "INSTALL_FAILED_UID_CHANGED" issue still present if function names have spaces

Running Android Studio 1.4.1 with Kotlin plugin 1.0.0-beta-1103.

If I create a new project, convert MainActivity.java to Kotlin, enable Kotlin, and then add the following code, this problem (which was fixed in 1.0.0-beta-1103) happens once again:

 
fun ` `() {

}



Now, when trying to run on my device (Sony Xperia M, running Android 4.1.2), I get this:

Installing com.example.kotlin DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.kotlin"      pkg: /data/local/tmp/com.example.kotlin Failure [INSTALL_FAILED_UID_CHANGED]

DEVICE SHELL COMMAND: pm uninstall com.example.kotlin
Unknown failure


Note that removing the space-name function does not resolve this.  Once this issue has occurred, it doesn’t seem to go away.

Wait. You can create a function that has whitespace as its name?

Surely that is a bug.

For more info, this Android issue seems to occur whenever a function has ' ' in its name.  For example, the following also triggers it:

package com.example.kotlin

import android.R
import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
  }
}

fun has space() {

}



Once this occurs, removing the function (which isn’t enough to fix this problem) and choosing Build > Clean Project fails with the following error:

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]

Configuration on demand is an incubating feature.
:clean UP-TO-DATE
:app:clean FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:app:clean’.
    > Unable to delete file: C:Testappbuildintermediatesexploded-aarcom.android.supportappcompat-v723.0.1jarsclasses.jar

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.813 secs


So, once this issue has occurred, everything seems to fall apart, and I’m not sure how to fix it.

This is not a bug, whitespaces in names are supported by the VM and are very helpful e.g. in tests vs camel case:

@Test fun `test that this thing goes here and that goes there`() {

  ... }

My mind is boggling right now. Surely the assumption that methods don't have spaces in their names is hard-coded at a very deep level in all kinds of software? I can't imagine this working well with the wider ecosystem of tools.

If the Android toolchain doesn't support spaces in method names, then there is nothing the Kotlin team could do to fix that, other than highligthting such methods as errors and thus preventing the possibility of using them in environments where spaces work fine.

This seems to be a big problem for Android development, a platform Kotlin explicitly supports (from today's blog post: "We are extremely pleased to present Kotlin 1.0 Beta for JVM and Android!").

It’s not like this users can simply remove the space-name function – as far as I can see, the project is broken from that moment on.

Is the team really willing to release 1.0 with this issue in place? I think anyone new to Kotlin who stumbled upon this issue would drop Kotlin in an instant. (I’m assuming the problem goes away when Kotlin is removed from the project, but I’m not even sure of that, and I can’t check right now.)

It is common practice in other languages such as Scala and Groovy to use spaces in test function names so it's definitly not a bug

The project getting stuck in a broken state is a bug that we're definitely going to investigate and fix if it really exists. It's also fairly likely that we'll be able to provide additional  diagnostics if we detect that a project with names containing bad characters is being  compiled for Android, so that the user would see a clear error from the  compiler instead of a cryptic one from the runtime.

As for the possibility to use spaces in method names, I really don’t see why this is so necessary for Android development, and why someone would drop Kotlin in an instant if they discovered that they don’t have this possibility.

I meant that they would drop Kotlin if they encountered this error and ended up with a broken project.

Glad to hear this is going to be investigated.

Dmitry,

There are a lot of intermediate steps in the Android build process, most of which are not under the developer’s control. It’s quite possible that some of these steps might be generating methods with spaces in them, and even if it’s not the case today, it might be the case in the future.

I strongly suggest making sure this works fine before shipping 1.0, it will be a big let down in the Android community otherwise, especially after years of Kotlin working fine on Android.

There really isn't anything that Kotlin can do about this. For example, Groovy also allows spaces in method names and a library that contains such a name will also break your Android build. The only solution is not to use white spaces in method names if you plan on targeting Android.

On a side note, seems like a rather peculiar method name to me…

I don't feel that this comment addresses the real issue — once a function with a space in its name has been defined and a build is attempted, the build is broken from that moment on.  Even after a code revert, building fails.

Does it crash if kotlin dependencies use spaces in method names? If that is the case, it may make using kotlin dependencies on android problematic.

In a small experiment, I created a kotlin library with an empty method named test method and didn’t call it anywhere in the library. I installed this library into my local maven repository. I added it as a dependency to a working android project and it wouldn’t load after that. I removed the empty method and it worked fine with the same dependency. Can anyone repeat this experiment to confirm the results?