Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Absolute path is not resolved in v0.14.2 when extending activity #592

Closed
RoyiNamir opened this issue Jul 2, 2018 · 3 comments
Closed

Absolute path is not resolved in v0.14.2 when extending activity #592

RoyiNamir opened this issue Jul 2, 2018 · 3 comments
Assignees

Comments

@RoyiNamir
Copy link

RoyiNamir commented Jul 2, 2018

Even after using the latest merged version :

"nativescript-dev-webpack": "^0.14.2",

Using this command tns build android --bundle

Works Good:

 const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        "./activity.android.ts"
    ];

But there's an error with this :

 const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/activity.android.ts")

    ];

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:C:\r\a\platforms\android\app\src\main\java\org\myApp\MainActivity.java Class: org.myApp.MainActivity
at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:78)
at org.nativescript.staticbindinggenerator.Main.main(Main.java:48)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:runSbg'.

image

(After tns platform remove android && tns platform add android - many times).

Here is a Sample empty project which shows the problem

Related info :

Windows 10 
C:\r\a>tns info
√ Getting NativeScript components versions information...
√ Component nativescript has 4.1.2 version and is up to date.
√ Component tns-core-modules has 4.1.0 version and is up to date.
√ Component tns-android has 4.1.3 version and is up to date.
‼ Update available for component tns-ios. Your current version is 4.1.0 and the latest available version is 4.1.1.

package.json

@RoyiNamir RoyiNamir changed the title Absolute path is not resolved (still) in 0.14.2 when extending activity Absolute path is not resolved in v0.14.2 when extending activity Jul 2, 2018
@NickIliev
Copy link
Contributor

@RoyiNamir the error indicates a different error that is not related to the paths in Windows.
I am using this POC application to bundle on Windows and the bundling is successful on my side - the application is using extended activity and custom background services files. Here are the paths in the webpack.config.js

In your case, the static binding generation has failed for some reason. I would suggest reseting your project with the following steps.

// store the added lines of code for your webpack config.js and delete all of the below
rm -rf node_modules platforms hooks webpack.config.js 

npm i
// add the extended activity to the newly generated webpack.config.js
tns platform add android
tns build android --bundle
tns run android --bundle

Please let me know if you have a specific scenario or code invloved to reproduce your error.

@RoyiNamir
Copy link
Author

RoyiNamir commented Jul 2, 2018

@NickIliev Hi Nick. Code involved - ( here it is )

Here are the steps - Exactly(!) as you said ^

Before delete :
btw (rm -rf is for mac , I'm on windows , just saying)

image

After delete :

image

Npm install :

image

Adding the activity :

   const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        resolve(__dirname, "app/activity.android.ts")
        
    ];

tns platform add android :

image

tns build android --bundle
Getting error ( same as I mentioned) :

Webpack compilation complete.
Project successfully prepared (android)
Executing after-prepare hook from C:\r\a\hooks\after-prepare\nativescript-dev-webpack.js
Building project...
Gradle build...
+ setting applicationId
+ applying user-defined configuration from C:\r\a\app\App_Resources\Android\app.gradle
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: C:\r\a\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
Warning: there already is an extend called org.myApp.MainActivity.
Warning: The static binding generator will generate extend from:vendor.js implementation
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:C:\r\a\platforms\android\app\src\main\java\org\myApp\MainActivity.java Class: org.myApp.MainActivity
at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:78)
at org.nativescript.staticbindinggenerator.Main.main(Main.java:48)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:runSbg'.

Process 'command 'C:\Program Files\Java\jdk1.8.0_172\bin\java.exe'' finished with non-zero exit value 1

image

HOWEVER - Changing it to :

  const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        "./activity.android.ts"

    ];

running - tns build android --bundle ( after tns platform remove/add)

Does work :

image

@NickIliev
Copy link
Contributor

@RoyiNamir the issue seems to be caused by an export and import of a variable from your extended activity. There are two possible workaround for your case

Workaround 1 (wont work on iOS as it will require to import a platform-specific file)

import { AndroidOnRouteToURL } from "./activity";

to

import { AndroidOnRouteToURL } from "./activity.android";

in app.component.ts

Workaround 2

As @RoyiNamir has pointed out the solution is to use a relative path (in webpack.config.js) for the extend activity.

const appComponents = [
        "tns-core-modules/ui/frame",
        "tns-core-modules/ui/frame/activity",
        "./activity.android.ts"

    ];

The above will work on both Android and IOS but will disable build on MAC with snapshot (--env,snapshot). This won't affect Windows builds. Another thing to notice is that in such cases there will be two files created and the extended activity will be in the bundle and not in the vendor.

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

No branches or pull requests

2 participants