I need your guidence about environmental vaariable in ruby.
================================================
I have some code that convert version of device intedtifier => device name..
in my code,
path:
Config-initilizer-android.rb
module Android
#conversion_table_of_model_id_and_device_name = {
'Anroid2,3' => 'Gingerbread',
'Android3,0' => 'Honeycomb',
'Android4,1' => 'ICS',
'Android4,2' => 'JB',
}
in the future, if there's another name of android eg.'KitKat'. i want to add it using environment variable not use the hard code.
how can i to do it? is it possible to that?
where should i put it?
regards.
agstwn
With Rails 4.1 you can use secrets.yml, check out this link
If you have earlier version, try figaro gem
What blocks you from using ENV constant?
module Android
#conversion_table_of_model_id_and_device_name = {
'Anroid2,3' => 'Gingerbread',
'Android3,0' => 'Honeycomb',
'Android4,1' => 'ICS',
'Android4,2' => 'JB',
'Android4,3' => ENV[ 'ANDROID_OS_NAME' ]
}
You have to remember that ENV vars are still variables, meaning you can use them in a similar way. I'd propose using something like the new secrets.yml in Rails 4.1, or something like config spartan to create a yml structure of the data you need:
#config/secrets.yml
development:
android:
2.3: "gingerbread"
3.0: "Honeycomb"
4.1: "ICS"
4.2: "JB"
4.4: "KK"
module Android
#conversion_table_of_model_id_and_device_name
me = {}
Rails.application.secrets.android.each do |k,v|
me[k.to_sym] = v
end
end
Related
I need to add those to Android files:
android:usesCleartextTraffic="true" and <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
But I'm using managed workflow and I don't know how to add those lines to app.json file.
I did this plugin which seems to work:
const { createRunOncePlugin, withAndroidManifest } = require('#expo/config-plugins');
const withAndroidManifestHavingBetterSecuritySettings = config => {
return withAndroidManifest(config, config => {
const androidManifest = config.modResults.manifest;
const mainApplication = androidManifest.application[0];
if(process.env.CHANNEL !== 'dev') {
androidManifest.$ = {
...androidManifest.$,
'xmlns:tools': 'http://schemas.android.com/tools',
};
mainApplication.$['tools:replace'] = 'android:usesCleartextTraffic';
mainApplication.$['android:usesCleartextTraffic'] = 'false';
}
return config;
});
};
module.exports = createRunOncePlugin(
withAndroidManifestHavingBetterSecuritySettings,
'withAndroidManifestHavingBetterSecuritySettings',
'1.0.0'
);
I had many issues related to merging of AndroidManifest files when "developmentClient": true in my eas.json file (related to me dev eas profile). I believe that it's related to the fact that the debug/AndroidManifest is a higher priority manifest than main/AndroidManifest (not sure though). So my solution was not to ignore the changes when building the dev profile. Hardening security settings in development builds do not seem useful anyhow.
So I struggled with this problem for a while now and the only solution I could come up with was setting the minimum sdk version of the android app from 21 to 28. This is not ideal as my application now does not support old android devices, but doing this defaults the usesClearTextTraffic flag to false.
If your app works fine while developing in expo, but after generating the APK some functions don't work, try this. In my case the APK crashed on login, but building in development with expo was working fine. The problem was that traffic is encrypted so that's why I ended up here trying to set clear text traffic. The problem in my case was with expoPushToken, in the APK it throws an exception I wasn't catching (building with expo worked fine as I said before, no exception). So, if the exception happens just catch it and set the token to empty string.
So, I had this:
import * as Notifications from "expo-notifications";
export async function getDevicePushTokenForAPP() {
const pushToken = await Notifications.getExpoPushTokenAsync();
return pushToken.data;
}
So then, I added the try and catch:
export async function getDevicePushTokenForAPP() {
try {
const pushToken = await Notifications.getExpoPushTokenAsync();
return pushToken.data;
} catch (e) {
return "";
}
}
Now if you build the APK again (expo build:android) it should work fine, in my case login worked. But please note this is for testing purposes only, I needed the APK to quickly show it to the client. (Note that you will need the bundle, not the apk, when uploading to the Playstore). This is a quick fix for you to test the APK; but with no token, push notifications won't work. The final fix is to add firebase to your project, it's mandatory now, so add firebase and with the firebase unique ID, your push notification will work in your APK.
My conclusion is that expo uses its own ID to communicate with firebase, that's why it works while developing but the APK doesn't go through expo and tries to connect to firebase directly, but crashes because there's no ID.
You should update your app.json like that:
"android": {
"usesCleartextTraffic": true,
uses-permission android:name
},
I'm building a react-native app that uses tensorflow to recognize images, I'm following the steps in this tutorial.
I did everything according to the explanations, including the part of "Fetching files". I created the assets folder and put the files in it (the path is correct).
But when I run this code:
const tfImageRecognition = new TfImageRecognition({
model: require('./assets/tensorflow_inception_graph.pb'),
labels: require('./assets/tensorflow_labels.txt'),
});
The app gives the following error:
I already tried to create a new project, I imported the react-native-tensorflow import { TfImageRecognition } from 'react-native-tensorflow';, I updated the cache, I deleted the folder node_modules and also I created the file "rn-cli.config.js" that is requested in the tutorial to give access to the files in the assets folder. Any idea how to fix this?
I'm using expo to run the app on mobile (android).
npm: 5.51
expo: 51.4.0
react-native: 0.54.0
react-native-cli: 2.0.1
This problem didn't occur with me. Try react-native start --reset-cache and then run the app again.
There is a better way to this.
import model from './assets/tensorflow_inception_graph.pb';
import labels from './assets/tensorflow_labels.txt';
const tfImageRecognition = new TfImageRecognition({
model,
labels
});
Restart your server.
I tried the same example as you mentioned I got accessed Image and Text.
I stored files inside assets in the same directory. Can you share code to produce an error that you faced?
async recognizeImage() {
try {
const tfImageRecognition = new TfImageRecognition({
model:require('./assets/tensorflow_inception_graph.pb'),
labels: require('./assets/tensorflow_labels.txt')
})
const results = await tfImageRecognition.recognize({
image: this.image
})
const resultText = `Name: ${results[0].name} - Confidence: ${results[0].confidence}`
this.setState({result: resultText})
await tfImageRecognition.close()
} catch(err) {
alert(err)
}
}
As you mentioned your using expo then I'm assuming that run npm eject already. As react-native-tensorflow this library require native changes
You must add extensions in your rn-cli.config.js, in order to require tensorflow_inception_graph.pb and tensorflow_labels.txt
module.exports = {
getAssetExts() {
return ['pb', 'txt']
}
}
Replace ./ with so ../ , so final code will be -
model: require('../assets/tensorflow_inception_graph.pb'),
labels: require('../assets/tensorflow_labels.txt')
I am unable to launch the android emulator to run my automation script.
However my automation script works when I launch the android emulator manually from the /Android/sdk/tools directory using emulator -avd Pixel_API_25 -port 5557.
I want to be able to load the android emulator within my automation script.
Please see my env.rb file below.
require 'rubygems'
require 'rspec/expectations'
require 'selenium-webdriver'
require 'pry'
require 'appium_lib'
APP_PATH = '/Users/shafiq.malik/Documents/Projects/nuff-class-booking-
mobile/platforms/ios/build/emulator/HelloCordova.app'
desired_caps = {
caps: {:platformName => "Android",
:platformVersion => "7.1.1",
:deviceName => "Pixel_API_25",
:app => "/Users/shafiq.malik/Documents/Projects/nuff-
class-booking-
mobile/platforms/android/build/outputs/apk/android-
debug.apk",
:appPackage => "com.android.settings",
#:appActivity => ".Settings",
:browserName =>''
}
}
#driver = Appium::Driver.new(desired_caps).start_driver
Appium.promote_appium_methods self.class
def server_url
'http://localhost:8000/wd/hub'
end
Does anyone have any suggestions?
Try adding this to your desired capability . You need avd capability in order to start the emulator.
In java
capabilities.setCapability("avd","AndroidTestDevice");
In case of ruby, Any one of these two.
avd: "AndroidTestDevice",
:avd => "AndroidTestDevice",
Your desired caps should something look like this
desired_caps = {
caps: {:platformName => "Android",
:platformVersion => "7.1.1",
:deviceName => "Pixel_API_25",
:app => "/Users/shafiq.malik/Documents/Projects/nuff-
class-booking-
mobile/platforms/android/build/outputs/apk/android-
debug.apk",
:appPackage => "com.android.settings",
`:avd => "AndroidTestDevice",`
#:appActivity => ".Settings",
:browserName =>''
}
}
On a side note, don't give a root directory as a file path to your application. This might later cause problems if you are using CI's , instead have a generic code where you only indicate, the .apk or .app/.ipa name.
I am trying to use this sms plugin - https://github.com/Ivanezko/Phonegap-SMS in my ionic android application. I am following the Readme documentation to install the plugin. In the second step author asked to do -
Require the plugin module
var smsplugin = cordova.require("info.asankan.phonegap.smsplugin.smsplugin");
What this statement means and where should I include this code to make use of this plugin?
I tried to do this in my controller file and its giving error cordova is not defined.
I tried debugging a little more in an emulator and the error given in the require statement is - module info.asankan.phonegap.smsplugin.smsplugin is not found.
First solution: 1. check that this plugin is wrapped by http://ngcordova.com/.
Second solution: 2. write wrapper = angular factory:
.factory('factoryname', ['$q', '$window','$state', function ($q,$window, $state) {
return {
function1: function () {
var q = $q.defer();
if (!$window.cordova) {
q.reject('Not supported without cordova.js');
} else {
secrettext.function1();
return q.promise;
},
3th solutions: add ['$window'] dependency to module you want use plugin. and use secrettext.function1();
*sectretext its clobbers from plugin xml
4 th solutions copy and paste this js code into you angular code on top of it and use function1();
I have created a simple universal app targeting Windows Phone 8.1 & Windows 8.1 in Visual Studio 2013.
I added an android project and implemented MvvmLight.
ViewmodelLocator, viewmodels & messaging all work fine.
Databinding also works for the windows projects.
When I try adding databinding within the android project - at run time I get an error Property not found: Text
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
var vm = ViewModelLocator.Main;
this.AddBinding(() => vm.AsyncCompleted,
() => bindingButton.Text,
BindingMode.TwoWay);
Has anyone else encountered this?
OK - solved it myself.
I was originally following an example from the mvvm light home page which doesn't seem to work with an Android project within a Universal App.
The answer is to specify the Actual control to add the binding to and pass the fully qualified View Model property to the binding:
Button bindingButton = FindViewById<Button>(Resource.Id.button1);
bindingButton.AddBinding(
() => ViewModelLocator.Main.AsyncCompleted,
() => bindingButton.Text,
BindingMode.OneWay);