Yes.
While trying to extend the default com.tns.NativeScriptApplication, I get dex merging errors on build.
app.gradledependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
defaultConfig {
multiDexEnabled true
}
}
main.tsimport * as application from 'application'
@JavaProxy('com.tns.NativeScriptApplication')
class Application extends android.app.Application implements android.app.Application {
onCreate(): void {
super.onCreate()
application.android.init(this)
}
attachBaseContext(base: android.content.Context) {
super.attachBaseContext(base)
android.support.multidex.MultiDex.install(this)
}
}
application.start({ moduleName: 'main-page' })
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ Component โ Current version โ Latest version โ Information โ
โ nativescript โ 2.5.0-2016-10-24-6930 โ 2.3.0 โ Up to date โ
โ tns-core-modules โ 2.5.0-2016-11-08-4705 โ 2.3.0 โ Up to date โ
โ tns-android โ 2.5.0-next-2016-11-08-1367 โ 2.3.0 โ Up to date โ
โ tns-ios โ โ 2.3.0 โ Not installed โ
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
Node v6.9.1
Java 8
Android 6.0.1
Execution failed for task ':myMergeDex'.
> Multiple dex files define Lcom/tns/NativeScriptApplication;
tns create sandbox --tsc
cd sandbox
npm install tns-core-modules@next
tns platform add android@next
<modify app.ts as stated above source>
tns run android
I used to be able to do this with v2.2.0, but sure what's happened since then. I'm only trying to extend the default com.tns.NativeScriptApplication, not create a new one.
I can easily extend the default com.tns.NativeScriptActivity like so:
@JavaProxy('com.tns.NativeScriptActivity')
class Activity extends android.app.Activity {
...
}
with no troubles at all.
Hi @roblav96,
it's not a good idead to try and initialize the modules in the onCreate method of the Applicaition class. See this issue for more info and detailed description of the problem.
@roblav96 did you manage to build your application?
@Plamen5kov Not the way described here, extending android.app.Application, but I worked around it at the time so I'm not able to try.
Hi @roblav96, i figured out what the problem was:
_Problem_:
We have a NativescriptApplication.java file, which is part of the template. We use this file to initialize the runtime with the following code:
public void onCreate() {
super.onCreate();
com.tns.Runtime runtime = RuntimeHelper.initRuntime(this);
if (runtime !=null) {
runtime.run();
}
}
When you make a javascript extend like you have:
@JavaProxy('com.tns.NativeScriptApplication')
class Application extends android.app.Application implements android.app.Application {
we create a dex implmentation of your javascript code and name it as you have specified in the @JavaProxy decorator. This creates a problem because there's a name conflict at build time as you pointed out in the error log.
_Solution_
AndroidManifest.xml.platforms/android/src/main/java/com/tns/NativeScriptApplication.java so there is only one file that's called this way, and there's no conflict.