Releted to this
I wrote a cross-platform app with NativeScript + Angular.
I create the .keystore file with this command (as shown in the documentation):
keytool -genkey -v -keystore <my-release-key>.keystore -alias <alias_name> -keyalg RSA -keysize 2048 -validity 10000
I build the release apk with this command:
tns build android --release --key-store-path "C:\Program Files\Java\jre1.8.0_201\bin\<name>.keystore" --key-store-password <password> --key-store-alias <alias> --key-store-alias-password <alias-password>
Then I installed the apk file on my Android devices (Android 9 and Android 8) but when I try to login ( => make a REST call) it does nothing. Nothing is shown, no errors and no calls made.
I'm using the version 6.2.0 of Nativescript. I found this problem after migrating the project to NativeScript 6.
Where am I wrong? Did I miss something?
UPDATE
I try the second command with run
instead of build
but the console doesn't show anything when I press the login button.
The console rimains stuck on this sentence:
Successfully installed on device with identifier 'xxxxxx'.
UPDATE
I deleted the 'hooks', 'node_modules' and 'platforms' folders and then rebuild the app but nothing changed.
UPDATE Here is the code of the button.
The first alert is raised when I press the button with empty email and empty password.
The second alert is raised when I press the button with all the credentials.
The third even the credentials are right is never raised.
login.component.ts
public login() {
if(!this.user.email || !this.user.password){
let options = {
title: 'ATTENZIONE!',
message: 'Inserire tutte le credenziali',
okButtonText: 'OK'
};
alert(options); //first
} else {
alert("HELLO WORLD!"); //second
this.userService.login(this.user).subscribe((res) => {
alert(res); //third
localStorage.setItem("authenticated", true);
localStorage.setItem("access_token", "bearer " + res.access_token);
localStorage.setItem("username", this.user.email);
},
(err)=>{
console.log("Something went wrong "+err);
alert("Credenziali errate");
return;
}
);
}
return;
}
user.service.ts
login(user: User) {
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('username', user.email);
urlSearchParams.append('password', user.password);
urlSearchParams.append('grant_type','password');
let body = urlSearchParams.toString();
var url = Config.apiUrl + "/token";
return this.http.post(url, body , { headers : this.getCommonHeaders() })
.map(res => res.json())
.catch( (error: any) => {Observable.throw(error.json().error)} );
}
http
is from @angular/http
I solved my problem changing the http client from Http
of @angular/core
(deprecated) to HttpClient
of @angular/common/http
.