-
-
Notifications
You must be signed in to change notification settings - Fork 140
Description
Please, provide the details below:
Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?
I have searched and been unable to find anything related to this issue.
Seems the use of @JavaProxy
decorator in TypeScript is quite limited with not many people discussing it.
Tell us about the problem
The Static Binding Generator fails to generate java classes for TypeScript classes if the TypeScript classes contain statics that are used by the class itself. The resulting javascript that is generated is different which I think is where the SBG is failing.
Note: this also occurs if using static members of parent classes through the TypeScript class (e.g. MyCustomActivity.RESULT_OK
)
Please provide the following version numbers that your issue occurs with:
- CLI: 4.2.2
- Cross-platform-modules: 4.2
- Runtime: 4.2
Did the error happen while the app was being constructed? (buildtime error)
No errors are emitted during compilation but this is where the problem occurs.
Did the error happen while the app was executing? (runtime error)
During runtime if you try to use the class (such as a custom activity) you will get a class not found exception due to no Java class having been generated.
Please tell us how to recreate the issue in as much detail as possible.
Example of a custom activity that is correctly being generated
testActivity.android.ts
import Bundle = android.os.Bundle;
@JavaProxy('com.test.Activity')
export class TestActivity extends android.app.Activity {
static readonly TEST1: string = "my_test";
public onCreate(savedInstanceState?: Bundle): void {
super.onCreate(savedInstanceState);
}
}
testActivity.android.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TestActivity = (function (_super) {
__extends(TestActivity, _super);
function TestActivity() {
return _super !== null && _super.apply(this, arguments) || this;
}
TestActivity.prototype.onCreate = function (savedInstanceState) {
_super.prototype.onCreate.call(this, savedInstanceState);
};
TestActivity.TEST1 = "my_test";
TestActivity = __decorate([
JavaProxy('com.test.Activity')
], TestActivity);
return TestActivity;
}(android.app.Activity));
exports.TestActivity = TestActivity;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdEFjdGl2aXR5LmFuZHJvaWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0ZXN0QWN0aXZpdHkuYW5kcm9pZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBO0lBQWtDLGdDQUFvQjtJQUF0RDs7SUFLQSxDQUFDO0lBSFUsK0JBQVEsR0FBZixVQUFnQixrQkFBMkI7UUFDdkMsaUJBQU0sUUFBUSxZQUFDLGtCQUFrQixDQUFDLENBQUM7SUFDdkMsQ0FBQztJQUhlLGtCQUFLLEdBQVcsU0FBUyxDQUFDO0lBRGpDLFlBQVk7UUFEeEIsU0FBUyxDQUFDLG1CQUFtQixDQUFDO09BQ2xCLFlBQVksQ0FLeEI7SUFBRCxtQkFBQztDQUFBLEFBTEQsQ0FBa0MsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLEdBS3JEO0FBTFksb0NBQVkiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgQnVuZGxlID0gYW5kcm9pZC5vcy5CdW5kbGU7XHJcblxyXG5ASmF2YVByb3h5KCdjb20udGVzdC5BY3Rpdml0eScpXHJcbmV4cG9ydCBjbGFzcyBUZXN0QWN0aXZpdHkgZXh0ZW5kcyBhbmRyb2lkLmFwcC5BY3Rpdml0eSB7XHJcbiAgICBzdGF0aWMgcmVhZG9ubHkgVEVTVDE6IHN0cmluZyA9IFwibXlfdGVzdFwiO1xyXG4gICAgcHVibGljIG9uQ3JlYXRlKHNhdmVkSW5zdGFuY2VTdGF0ZT86IEJ1bmRsZSk6IHZvaWQge1xyXG4gICAgICAgIHN1cGVyLm9uQ3JlYXRlKHNhdmVkSW5zdGFuY2VTdGF0ZSk7XHJcbiAgICB9XHJcbn0iXX0=
entry in sbg-bindings.txt
android.app.Activity*****onCreate,TEST1*com.test.Activity*testActivity.js*
resulting java class
/* AUTO-GENERATED FILE. DO NOT MODIFY.
* This class was automatically generated by the
* static binding generator from the resources it found.
* Please do not modify by hand.
*/
package com.test;
@com.tns.JavaScriptImplementation(javaScriptFile = "./testActivity.js")
public class Activity extends android.app.Activity implements com.tns.NativeScriptHashCodeProvider {
public Activity(){
super();
com.tns.Runtime.initInstance(this);
}
protected void onCreate(android.os.Bundle param_0) {
java.lang.Object[] args = new java.lang.Object[1];
args[0] = param_0;
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, args);
}
public void onCreate(android.os.Bundle param_0, android.os.PersistableBundle param_1) {
java.lang.Object[] args = new java.lang.Object[2];
args[0] = param_0;
args[1] = param_1;
com.tns.Runtime.callJSMethod(this, "onCreate", void.class, args);
}
public boolean equals__super(java.lang.Object other) {
return super.equals(other);
}
public int hashCode__super() {
return super.hashCode();
}
}
Example of a custom activity that is _NOT_ correctly being generated
testActivity.android.ts
import Bundle = android.os.Bundle;
@JavaProxy('com.test.Activity')
export class TestActivity extends android.app.Activity {
static readonly TEST1: string = "my_test";
public onCreate(savedInstanceState?: Bundle): void {
super.onCreate(savedInstanceState);
console.log(TestActivity.TEST1);
}
}
testActivity.android.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TestActivity = (function (_super) {
__extends(TestActivity, _super);
function TestActivity() {
return _super !== null && _super.apply(this, arguments) || this;
}
TestActivity_1 = TestActivity;
TestActivity.prototype.onCreate = function (savedInstanceState) {
_super.prototype.onCreate.call(this, savedInstanceState);
console.log(TestActivity_1.TEST1);
};
var TestActivity_1;
TestActivity.TEST1 = "my_test";
TestActivity = TestActivity_1 = __decorate([
JavaProxy('com.test.Activity')
], TestActivity);
return TestActivity;
}(android.app.Activity));
exports.TestActivity = TestActivity;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdEFjdGl2aXR5LmFuZHJvaWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0ZXN0QWN0aXZpdHkuYW5kcm9pZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBO0lBQWtDLGdDQUFvQjtJQUF0RDs7SUFNQSxDQUFDO3FCQU5ZLFlBQVk7SUFFZCwrQkFBUSxHQUFmLFVBQWdCLGtCQUEyQjtRQUN2QyxpQkFBTSxRQUFRLFlBQUMsa0JBQWtCLENBQUMsQ0FBQztRQUNuQyxPQUFPLENBQUMsR0FBRyxDQUFDLGNBQVksQ0FBQyxLQUFLLENBQUMsQ0FBQztJQUNwQyxDQUFDOztJQUplLGtCQUFLLEdBQVcsU0FBUyxDQUFDO0lBRGpDLFlBQVk7UUFEeEIsU0FBUyxDQUFDLG1CQUFtQixDQUFDO09BQ2xCLFlBQVksQ0FNeEI7SUFBRCxtQkFBQztDQUFBLEFBTkQsQ0FBa0MsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLEdBTXJEO0FBTlksb0NBQVkiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgQnVuZGxlID0gYW5kcm9pZC5vcy5CdW5kbGU7XHJcblxyXG5ASmF2YVByb3h5KCdjb20udGVzdC5BY3Rpdml0eScpXHJcbmV4cG9ydCBjbGFzcyBUZXN0QWN0aXZpdHkgZXh0ZW5kcyBhbmRyb2lkLmFwcC5BY3Rpdml0eSB7XHJcbiAgICBzdGF0aWMgcmVhZG9ubHkgVEVTVDE6IHN0cmluZyA9IFwibXlfdGVzdFwiO1xyXG4gICAgcHVibGljIG9uQ3JlYXRlKHNhdmVkSW5zdGFuY2VTdGF0ZT86IEJ1bmRsZSk6IHZvaWQge1xyXG4gICAgICAgIHN1cGVyLm9uQ3JlYXRlKHNhdmVkSW5zdGFuY2VTdGF0ZSk7XHJcbiAgICAgICAgY29uc29sZS5sb2coVGVzdEFjdGl2aXR5LlRFU1QxKTtcclxuICAgIH1cclxufSJdfQ==
entry in sbg-bindings.txt
android.app.Activity*testActivity***TestActivity*onCreate,TEST1***
resulting java class
N/A, java class is not generated