I build my deployment release via Docker.
command: ["flutter", "pub", "global", "run", "webdev", "serve", "--hostname", "0.0.0.0", "web:5001", "--release"]
I have defined part of the code which retrieve different value based on the environment. Either it's production or development.
import 'package:flutter_web/foundation.dart';
....
static getEnvironment() {
if (kReleaseMode) {
return "production";
} else {
return "development";
}
}
However, even after building a release build, after calling getValue method I receive development value.
What I do wrong here?
Related
In my unit tests for my Roslyn analyzer, I need to use Microsoft.AspNetCore.Mvc in the test code string. I believe that means I need the long form of testing, so I did the following.
var expected = VerifyCS.Diagnostic(MyAnalyzer.DiagnosticId)
.WithLocation(0)
.WithArguments("Method");
var assemblies = ReferenceAssemblies
.Default
.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.AspNetCore.Mvc.Core", "6.0.0.0")));
await new VerifyCS.Test {
ReferenceAssemblies = assemblies,
TestState = {
Sources = {
test
},
ExpectedDiagnostics = {
expected
}
}
}.RunAsync();
When running the test, it tells me:
Unable to find package 'Microsoft.AspNetCore.Mvc.Core'. Existing packages must be restored before performing an install or update.
I'm not sure how to resolve that in the unit test.
I have web server written in golang which uses graphql package gqlgen and gorm for database.
Since golang can be compiled and run on android I wanted to create offline version of my app where sqlite can be used for offline storage and import my whole server as an aar.
I have successfully built aar and add it on my flutter using gomobile by following instructions here
When I run my app, server is started on android it seems to work just fine and when opening http://localhost:8080/ on emulator's chrome app I am seeing graphql playground runs without any problem just like I see on browser in windows.
The only problem I face is that flutter app just shows a blank screen while server runs in background. The following are the logs printed when app is started
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:62561/DyGpOhyuekw=/ws
Syncing files to device sdk gphone64 x86 64...
I/GoLog ( 6295): connect to http://localhost:8080/ for GraphQL playground
W/ux.offline( 6295): type=1400 audit(0.0:38): avc: denied { read } for name="somaxconn" dev="proc" ino=74990 scontext=u:r:untrusted_app:s0:c149,c256,c512,c768 tcontext=u:object_r:proc_net:s0 tclass=file permissive=0 app=com.nux.offline
I think maybe problem lies on the above logs avc: denied { read } for name="somaxconn" or something is causing the blocking of ui thread since its like flutter don't render a thing.
I am using flutter plugin to start server and this is ServerPlugin.kt
package com.mahesabu.server.server
import androidx.annotation.NonNull
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import lib.Lib.startServer
/** ServerPlugin */
class ServerPlugin : FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel: MethodChannel
override fun onAttachedToEngine(#NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "server")
channel.setMethodCallHandler(this)
}
override fun onMethodCall(#NonNull call: MethodCall, #NonNull result: Result) {
if (call.method == "startServer") {
try {
val port = startServer() //from golang bindings
result.success(port)
} catch (e: Exception) {
e.printStackTrace();
result.error("Error in starting server", "${e.message}", null);
}
} else {
result.notImplemented()
}
}
override fun onDetachedFromEngine(#NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
And this is is dart code
class Server {
static const MethodChannel _channel = MethodChannel('server');
static Future<String?> startServer() async {
try {
final String? port = await _channel.invokeMethod('startServer');
return port;
} catch (e) {
log('startServer error: ${e.toString()}');
return null;
}
}
}
and my app's main is as follows
import 'package:flutter/material.dart';
import 'package:server/server.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final port = await Server.startServer(); //problem
print('port $port'); //This don't print
runApp(const MyApp());
}
On go side this how i start server
//start.go
package util
import (
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"log"
"my-project/graph"
"my-project/graph/generated"
"net/http"
"os"
)
const defaultPort = "8080"
// StartServer This way so that it can be invoked via libs
func StartServer(Offline bool) string {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
db := InitDB(Offline)
config := generated.Config{Resolvers: &graph.Resolver{
DB: db,
}}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(config))
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
return port
}
and this is lib for generating bindings with gomobile
//lib.go
package lib
import "my-project/util"
// StartServer This way so that it can be invoked via libs
func StartServer() string {
return util.StartServer(true)
}
Any help on fixing this will be appreciated.
Edit
I think problem occurs when embedded server tries to create a new port. I don't know if it is possible for an app to open a new port in android just like nodejs, golang open things like http://localhost:8080.
Now I think if there is a way to create port then I can run my app successfully but I don't know how exactly.
I was thinking if I can find any available port on android and use to start server maybe this stack could be possible. In kotlin something like this may work in finding port.
import java.net.ServerSocket
fun main() {
val serverPort = ServerSocket(0)
print(serverPort.toString())
}
but it crashes on android app when I try similar thing.
I have uploaded a repository on GitHub showing what I intend to do. It's just a simple golang server using gin and android app (with no flutter) it is available here.
"I don't know if it is possible for an app to open a new port in android just like nodejs, golang open things like localhost:8080"
To find out the root cause, try to run an HTTP server in android, such as How to create a HTTP server in Android?. If that succeeds, try to find the differences about how they deal with ports.
In addition, please be sure you have correct permission in androidmanifest.xml.
(Rephrased from my comments)
Am really struggling with this and the only examples I can seem to find are for cmdlets to be run not scripts cloned from a Git repo. I have the following:
pipeline {
environment {
JOB_BASE_NAME="org-onprem-2016"
VERSION="$BUILD_NUMBER"
teamsColorRed="C50E2E"
teamsColorGreen="7FBA00"
}
// Helper function to run PowerShell Commands
agent {
node {
label 'Windows'
}
}
stages {
stage('Checkout SCM') {
steps {
step([$class: 'WsCleanup'])
dir ('inv_onprem_2016') {
git url: 'https://github.local/org-cit/org_onprem_2016.git', credentialsId: 'svc-tokenauth'
}
}
}
stage('Initiate Build Variables') {
steps {
powerShell('scripts\\2012\\initiatevars.ps1')
}
}
I have tried multiple iterations over the steps bit but always get some form of error around path not found etc. I think I am missing how the workspace should be addressed but tried $ENV:WORKSPACE in front and got the same result (different error around no "ENV" being defined). Can anyone help steer me in the right direction for this?
Downloaded from GitHub, to make moudle 'ReactAndroid', then:
Error:(687) Android NDK: Module reactnativejnifb depends on undefined modules: fbjni
Error:(700) *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)
Error:Execution failed for task ':ReactAndroid:buildReactNdkLib'.
Process 'command '/Users/sumomokawaakira/Downloads/adt-bundle-mac-x86_64/sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2
I had this problem too. I think you can fix it by making sure you are using the precisely correct version of the Android NDK (android-ndk-r10e).
Also make sure that you set the environment variables and stuff done right.
(For what it's worth I'm stuck on later steps, but hopefully this should help you get passed this particular issue)
You have to change your path to ANDROID_NDK to run gradle command locally.
export ANDROID_NDK=/Users/your_unix_name/android-ndk/android-ndk-r10e
In my case, I put NDK file at /Users/tomo/temp/android-ndk-r10e
so
export ANDROID_NDK=/Users/tomo/temp/android-ndk-r10e
Or if you do not want to change ANDROID_NDK, you can update ReactAndroid/build.gradle
def findNdkBuildFullPath() {
// we allow to provide full path to ndk-build tool
if (hasProperty('ndk.command')) {
return property('ndk.command')
}
// or just a path to the containing directory
if (hasProperty('ndk.dir')) {
def ndkDir = property('ndk.dir')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
// ** Add below. should be before if (System.getenv('ANDROID_NDK') clause **
Properties properties = new Properties()
properties.load(project.rootProject.file('ReactAndroid/local.properties').newDataInputStream())
if (properties.hasProperty('ndk.dir')) {
def ndkDir = properties.getProperty('ndk.dir')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
if (System.getenv('ANDROID_NDK') != null) {
def ndkDir = System.getenv('ANDROID_NDK')
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
plugins.getPlugin('com.android.library').hasProperty('sdkHandler') ?
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder() :
android.ndkDirectory.absolutePath
if (ndkDir) {
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
}
return null
}
then update ReactAndroid/local.properties
ndk.dir=/Users/tomo/temp/android-ndk-r10e
sdk.dir=/Applications/sdk
and Run app from Android Studio
for React Native 7.0
try either :
rm -rf node_modules && yarn install (worked for me)
or
These steps:
Close Android Studio
Add android.disableAutomaticComponentCreation=true in android/gradle.properties
Reopen project and build.
I have a custom AMI which runs my service. Using the AWS Java SDK, I create an EC2 instance using RunInstancesRequest from the AMI. Now before I begin to use my service, I must ensure that the newly created instance is up and running. I poll the instance using:
var transitionCompleted = false
while (!transitionCompleted) {
val currentState = instance.getState.getName
if (currentState == desiredState) {
transitionCompleted = true
}
if(!transitionCompleted) {
try {
Thread.sleep(TRANSITION_INTERVAL)
} catch {
case e: InterruptedException => e.printStackTrace()
}
}
}
So when the currentState of the instance turns into desiredState(which is running), I get the status that the instance is ready. However any newly created instance, despite being in running state, is not available for immediate use as it is still initializing.
How do I ensure that I return only when I'm able to access the instance and its services? Are there any specific status checks to make?
PS: I use Scala
You are checking instance state, while what you are actually interested in are the instance status checks. You could use describeInstanceStatus method from the Amazon Java SDK, but instead of implementing your own polling (in a non-idiomatic Scala) it's better to use a ready solution from the SDK: the EC2 waiters.
import com.amazonaws.services.ec2._, model._, waiters._
val ec2client: AmazonEC2 = ...
val request = new DescribeInstanceStatusRequest().withInstanceIds(instanceID)
ec2client.waiters.instanceStatusOk.run(
new WaiterParameters()
.withRequest(request)
// Optionally, you can tune the PollingStrategy:
// .withPollingStrategy(...)
)
)
To customize polling delay and retry strategies of the waiter check the PollingStrategy documentation.