Nativescript WebPack java.io.IOException: File already exists


#1

Hi guys,
I have 3 classes defined this way:

@JavaProxy("com.tns.notifications.TestProxy") class Test extends com.google.firebase.iid.FirebaseInstanceIdService { onTokenRefresh(){ ... } } }

when I build with tns build android --bundle i have this error:

Exception in thread “main” java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:/----/platforms/android/app/src/main/java/com/tns/notifications/Test.java Class: com.tns.notifications.TestProxy

tns --version ==> 4.1.0-2018-04-18-11407

{
"description": "",
"license": "SEE LICENSE IN ",
"readme": "NativeScript Application",
"repository": "",
"nativescript": {
"id": "***",
"hooks": [
{
"type": "before-prepare",
"script": "app.entitlements.js"
},
{
"type": "before-prepare",
"script": "build-gradle-template.js"
},
{
"type": "before-prepare",
"script": "copy-google-services.js"
}
],
"tns-android": {
"version": "4.1.0-2018.4.18.2"
},
"tns-ios": {
"version": "4.0.2-2018-04-18-01"
}
},
"dependencies": {
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"": "~5.0.0",
"angular2-jwt": "^0.2.3",
"angular2-moment": "^1.8.0",
"base-64": "^0.1.0",
"buffer": "^5.0.8",
"file-system": "^2.2.2",
"http": "0.0.0",
"moment-timezone": "^0.5.14",
"nativescript-angular": "^5.0.0",
"nativescript-background-http": "^3.1.0",
"nativescript-camera": "^4.0.2",
"nativescript-carousel": "^3.1.1",
"nativescript-checkbox": "^3.0.3",
"nativescript-drop-down": "^3.2.1",
"nativescript-geolocation": "^4.2.3",
"nativescript-google-maps-sdk": "^2.6.0",
"nativescript-image-cache": "^1.1.6",
"nativescript-imagepicker": "^5.0.2",
"nativescript-iqkeyboardmanager": "^1.3.0",
"nativescript-linearprogressbar-elica": "^1.0.0",
"nativescript-localize": "^2.1.0",
"nativescript-localstorage": "^1.1.5",
"nativescript-mediafilepicker": "^1.0.5",
"nativescript-number-progressbar": "^1.0.0",
"nativescript-orientation": "^2.2.0",
"nativescript-phone": "^1.3.1",
"nativescript-photoviewer": "^1.4.0",
"nativescript-pulltorefresh": "^2.1.0",
"nativescript-theme-core": "~1.0.2",
"nativescript-ui-chart": "^3.5.0",
"nativescript-ui-listview": "^3.5.1",
"ng2-translate": "^5.0.0",
"path": "^0.12.7",
"reflect-metadata": "~0.1.8",
"rxjs": "^5.5.0",
"tns-core-modules": "^4.0.0",
"utf8": "^3.0.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"": "~5.0.0",
"": "~1.8.2",
"babel-traverse": "6.4.5",
"babel-types": "6.4.5",
"babylon": "6.4.5",
"copy-webpack-plugin": "~4.0.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.7.1",
"nativescript-dev-webpack": "^0.9.0",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"tns-platform-declarations": "^3.4.1",
"typescript": "~2.4.2",
"webpack": "~3.8.1",
"webpack-bundle-analyzer": "^2.8.2",
"webpack-sources": "~1.0.1"
}
}

Thanks all


#2

I had faced this issue when I had multiple defined classes with same name, since you mentioned you have 3 make sure all are unique.


#3

Thanks for reply.
The problem is that the classes are all of different names, I do not understand what it means with this error message.


#4

But the error log you have attached points to only TestProxy, so did you try to rename that / remove it just in case to see if that resolves the issue?


#5

I can not remove it because I have defined a service in AndroidManifest.xml


#6

That’s fine, for debugging purpose remove it from everywhere just to see if that resolves issue.


#7

Now i have this error:
System.err: java.lang.RuntimeException: Unable to instantiate service com.tns.notifications.TestProxy: java.lang.ClassNotFoundException: Didn’t find class "com.tns.notifications.TestProxy"


#8

if I also remove the services from AndroidManifest.xml then the build is done but I can not use the services that I have obviously deleted.


#9

Is the result same even when you try a different package + class name?


#10

yes, Is the result same


#11

Have you followed the steps that is specific to Webpack,

  1. Add your class name to mangle list if you are using UglifyJS or other obfuscate tools.
  2. Add the file path to NativeScriptSnapshotPlugin if you are using snapshot enabled builds
  3. Import the JavaScript file in your vendor-platform.android.ts

#12

yes I followed all the steps.
It seems to be a known problem.
Do you have any idea?


#13

I may not agree that is a known issue, as I have extended classes in my app, even the sample grocery app does I guess. So it may be something within your project, but without being able to see / debug the issue I couldn’t say much.


#14

in the mip package.json do you notice anything strange?
I simply extended the classes, I do not think there is something strange.


#15

Delete all the JS files in your project and run the commands again. If you had moved TS file from one location to another in past, the file in old location may be giving the conflict. This is one other stupid issue I stuck in past, not sure you case may be same.


#16

What’s the use of the this class anyway? AFAIK it’s not needed for the Firebase plugin.


#17

I’m not using the Firebase plugin.
I managed push notifications for both platforms natively.


#18

now I try, thanks :slight_smile:


#19

I tried to delete js files but it did not work, always the same problem.