Repository navigation
Closed
Labels
Description
Did you verify this is a real problem by searching Stack Overflow and the other open issues in this repo?
Yes.
Tell us about the problem
While trying to extend the default com.tns.NativeScriptApplication, I get dex merging errors on build.
Source
app.gradle
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
defaultConfig {
multiDexEnabled true
}
}
main.ts
import * 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' })Please provide the following version numbers that your issue occurs with:
┌──────────────────┬────────────────────────────┬────────────────┬───────────────┐
│ 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
Did the error happen while the app was being constructed? (buildtime error)
Execution failed for task ':myMergeDex'.
> Multiple dex files define Lcom/tns/NativeScriptApplication;
Please tell us how to recreate the issue in as much detail as possible.
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
Notes
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.
Reacted by okmttdhr, tada
Activity
Plamen5kov commentedon Nov 14, 2016
Hi @roblav96,
it's not a good idead to try and initialize the modules in the
onCreatemethod of theApplicaitionclass. See this issue for more info and detailed description of the problem.Plamen5kov commentedon Nov 28, 2016
@roblav96 did you manage to build your application?
roblav96 commentedon Nov 28, 2016
@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.Plamen5kov commentedon Dec 6, 2016
Hi @roblav96, i figured out what the problem was:
Problem:
We have a
NativescriptApplication.javafile, which is part of the template. We use this file to initialize the runtime with the following code:When you make a javascript extend like you have:
we create a dex implmentation of your javascript code and name it as you have specified in the
@JavaProxydecorator. 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.javaso there is only one file that's called this way, and there's no conflict.feat(runtime): make a file module's query part of its identity (#2176)