I am trying to integrate google_maps_flutter into an existing project.
The maps component works only when running directly the "my_flutter" project on the device (the same code).
When I try to run the flutter module from an existing app, the maps component is empty and no logs are available (or usable).
(Flutter doctor does not output any errors).
I've followed the steps for both the my_flutter/.iOS and my_flutter/.android projects and I also followed them for the projects that integrate my_flutter.
Source:
Android
Specify your API key in the application manifest
android/app/src/main/AndroidManifest.xml:
<manifest ...
<application ...
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="YOUR KEY HERE"/>
iOS
Specify your API key in the application delegate ios/Runner/AppDelegate.m:
include "AppDelegate.h"
include "GeneratedPluginRegistrant.h"
import "GoogleMaps/GoogleMaps.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GMSServices provideAPIKey:#"YOUR KEY HERE"];
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
#End
Opt-in to the embedded views preview by adding a boolean property to
the app's Info.plist file with the key
io.flutter.embedded_views_preview and the value YES.
I suspect that I what I am trying is not possible yet with the current version on the library and it may come as a new feature when the library is not in "developer preview".
Found that I had to:
GeneratedPluginRegistrant.register(with: flutterViewController.pluginRegistry());
Did you set a latitude and longitude in the Google Maps param?
If you're setting your API key and doing what it said, it should work fine
Related
Using App action test tools in Android Studio for testing Google Actions, I'm getting the error
Preview Creation Error Status Code: 400 Message: Precondition check failed.
The requested Android app package name does not have an associated project
in Play Console. Please create a draft in Play Console and upload an app
with package name 'com.example.yadayada'.
If I try to "upload an app with packagename ..."
I'm getting the error
Upload failed
You have uploaded an APK or Android App Bundle that contains an action schema
document in the manifest file, but the action patterns are not yet allowed.
If you participate in a beta program, you must obtain authorization
for your developer account
Ok, but where and how can i do it ?
Furthermore, I don't have to publish an application, this is just a draft to test the implementation of possible future Slices, and the documentation states that it is possible to do it through the Android Studio plugin.
Ok, got it. Hints here
Create a new application in developer console without actions, and use
its package name in the test application with actions. You can use any package names that you have already registered in Console
android {
defaultConfig {
applicationId "com.example.yadayada.playconsole"
}
}
You need to add this to the manifest file:
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
This is explained in the app actions tutorial and also here: https://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts#static
I have integrated firebase Crashlytics on a react native application. I want to disable crash logs while working on development mode. How can I disable crash logs in debug mode for both Android and Ios Application. To create crash logs I have followed react native firebase documentation check this official link :: https://rnfirebase.io/docs/v5.x.x/crashlytics/android
I am using react-native-firebase version 5.2.2
I want to disable logs on debug mode without changing the version. I want to add code to disable the crash log for both Android and Ios. Please suggest how this should be done.
The documentation explains how to disable it
iOS
Turn off automatic collection with a new key to your Info.plist file:
Key: firebase_crashlytics_collection_enabled
Value: false
<key>firebase_crashlytics_collection_enabled</key>
<false/>
Android
Turn off automatic collection with a meta-data tag in your AndroidManifest.xml file:
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
Enable collection at runtime
You can can initialise crashlytics in your javascript code using
firebase.crashlytics().enableCrashlyticsCollection();
You can then use
if (__DEV__) {
} else {
}
to run any specific code in development or in production.
I only need to set one line in firebase.json file,
{
"react-native": {
"crashlytics_debug_enabled": false
}
}
faced the same in one of my project : "react-native": "0.66.1"
Edit AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reversedomain">
<application
...
...
// add this line
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
</application>
install '#react-native-firebase/crashlytics'
add .env at the root of your project & set production = false
in app.js
import React from 'react'
import { production } from '#env';
import crashlytics from '#react-native-firebase/crashlytics';
useEffect(()=>{
if (production == true) {
// Enable on runtime
crashlytics().setCrashlyticsCollectionEnabled(true);
}
},[])
docs
To be clear on what i am asking i will provide a real world example. take look at this and notice the following section:
Hotline - Android SDK Integration Steps Modified on: Fri, 6 Oct, 2017 at 8:21 PM
Integrate Hotline SDK (Using Gradle) Pre Requisites :
Hotline SDK clients require devices running Android 2.3 or higher
Hotline App Id and App Key from here: Where to find App ID and App Key
Android Studio and Gradle
If you have any queries during the integration, please send it to us - Submit a Query
1. Add Hotline SDK to your app
Add the maven URL to the root build.gradle (project/build.gradle)
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Add the following dependency to your app module's build.gradle file
(project/app/build.gradle):
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.github.freshdesk:hotline-android:1.2.+'
}
1.1 Android target version supported
Hotline SDK supports apps targeting Android version 5.0+. The SDK
itself is compatible all the way down to Gingerbread (API Level 10).
When app targets Android 7.0+
When FileProvider is not configured for Hotline SDK, the following
error code is displayed
"Missing/Bad FileProvider for Hotline. Camera capture will fail in devices running Nougat or later versions of OS (error code 354)"
To fix this, please include the provider in the
AndroidManifest.xml as below and specify the authority in strings.xml.
Assuming, com.example.demoapp is the package name of your app, the
declaration would be
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.demoapp.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/hotline_file_provider_paths" />
</provider>
Strings.xml
<string name="hotline_file_provider_authority">com.example.demoapp.provider</string>
When app targets Android 8.0+
When the app's target is Android 8.0 or later, and by extension includes appcompat-v7 r26.0.0.+, you'll see the following errors
E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/freshdesk/hotline/activity/InterstitialActivity;
Hotline SDK's activities extends ActionBarActivity to keep the SDK
compatible with app's targeting older Android versions/appcompat-v7
revisions. It can be resolved by adding a proxy class
(ActionBarActivity was replaced by AppCompatActivity and was proxied
by lib itself since 24.2.0 of appcomapt-v7, until it was removed in
26.0.0) manually if you are building with support library 26.x.x.
Add the following class in the appropriate package
package android.support.v7.app;
public class ActionBarActivity extends AppCompatActivity {
}
my question has nothing to do with Hotline. But after i did what they asked my package structure looks like this:
now that you have some background let me tell you what i dont understand. Does this mean that i am overriding any calls in package android.support.v7.app.ActionBarActivity ? so does this mean that for any 3rd party build i have i can override its classes this way as long as i know the package and class name ?
Basically what does it mean to put package name of something i do not own into my package structure ? what does it do ?
UPDATE: look at this article here as another example . if you read solution 3 you see we can do the same thing with facebook.login. i personally implemented this and it works. my test package structure looks like this and it overrides facebooks loginCreator etc:
even though i implemented it, i still dont get whats happening. can someone explain ?
I have to integrate the flurry ad in my android application. Can anybody provide the steps to integrate the flurry ad. I have gone through official sdk for flurry but not get any idea. I have followed the link android: Flurry Ads Banner taking Full screen
I have used the code not get any results
FlurryAgent.onStartSession(this, getString(R.string.flurry_api_key));
FlurryAds.fetchAd(this, "ANDROID_BANNER_TOP", mBanner,
FlurryAdSize.BANNER_TOP);
Prerequisites
Flurry Analytics requires a minimum Android API level 10.
Flurry Analytics uses the Android Advertising ID provided by Google Play Services and will check for and respect the user’s ad tracking preference.
Get your API Keys
Start by creating an app. Once you create the app, you’ll receive a Flurry API Key, which you’ll need when using the SDK.
Download the Flurry Android SDK
There are currently two ways of getting the Flurry Android SDK into your application:
Install via jCenter (Recommended):
The Flurry SDK is available via jCenter. You can add it to your application by including the following in your build.gradle file:
// In your top level Gradle config file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
// In your main app's Gradle config file:
dependencies {
compile 'com.flurry.android:analytics:6.3.1'
/*
* Optional library to help in monetizing your app with ads.
* If you include the ads library, you do not need to include
* the analytics library as it is a transitive dependency.
*/
// compile 'com.flurry.android:ads:6.3.1'
//... other dependencies
}
Download .jar files from Flurry Dev Portal
The downloaded archive should contain these files for use with Flurry Analytics:
FlurryAnalytics_x.y.z.jar: The library containing Flurry’s analytic collection and reporting code (where x.y.x denotes the latest version of Flurry SDK).
FlurryAds_x.y.z.jar: The optional library to incorporate Flurry’s ads into your application (where x.y.x denotes the latest version of Flurry SDK).
ProjectApiKey.txt: This file contains the name of your project and your project’s API key.
FlurryAndroidAnalyticsReadmevx.y.z.pdf: A PDF file with instructions (where x.y.x denotes the latest version of Flurry SDK).
Add the FlurryAnalytics_x.y.z.jar to your classpath¶
Using Android Studio:
If using Android Studio, you do not need to do anything further to include the Flurry SDK in your project, as long as you have installed the SDK through jCenter in your Gradle configuration.
However, if you prefer to use the downloaded .jar files, follow these procedures:
Add FlurryAnalytics-5.x.x.jar to your project’s libs folder.
Navigate to File > Project Structure > Module > Dependencies. Click the ‘+’ button in the bottom of the ‘Project Structure’ popup to add dependencies. Select ‘File dependency’ and add libs/FlurryAnalytics-5.x.x.jar.
Add Google Play Services library. If selectively compiling individual Google Play Service APIs, you should include the Google Analytics API.
Using Eclipse
Add FlurryAnalytics-5.x.x.jar to your project’s libs folder. Right-click on each JAR file and select Build Path > Add to Build Path.
Add the Google Play Service library jar file.
Configure your AndroidManifest.xml
- Have access to the Internet and allow the Flurry SDK to check state of the network connectivity.
- Specify a versionName attribute in the manifest to have data reported under that version name.
- Declare min version of that Android OS that the app supports. Flurry supports Android OS versions 10 and above.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flurry.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<!--required permission-->
<uses-permission android:name="android.permission.INTERNET" />
<!--optional permission - highly recommended-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--optional permission -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MyApplication"
android:icon="#drawable/app_icon">
<!--your activities -->
</application>
</manifest>
Add calls to init, onStartSession and onEndSession
Follow these steps, adding these calls:
If you are shipping an app, insert a call to FlurryAgent.init(Context, String) in your Application class, passing it a reference to your application Context and your project’s API key:
//If you are shipping an app, extend the Application class if you are not already doing so:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
new FlurryAgent.Builder()
.withLogEnabled(false)
.build(this, FLURRY_API_KEY);
}
}
Alternatively, you may call init() just before onStartSession(). It is safe to call init() more than once, provided that you use the same API key throughout the application. You may use any type of Context you wish.
If you are writing an app and the minimum target is Ice Cream Sandwich or above (minSdkVersion is set to API level 14 or greater), session handling is completely automatic, and you may skip steps 3 and 4. If you are instrumenting another type of Context, such as a Service, or your minimum target is Gingerbread, proceed with steps 3 or 4.
Insert a call to FlurryAgent.onStartSession(Context) in the Activity’s onStart() method, passing it a reference to a Context object (such as an Activity or Service). If you are targeting Gingerbread, Flurry recommends using the onStart() method of each Activity in your app, and passing the Activity itself as the Context object. For services (or other Contexts), use the Service or the relevant Context as the Context object. Do not pass in the global Application context.
Insert a call to FlurryAgent.onEndSession(Context) in the Activity’s onStop() method, when a session is complete. If you are targeting Gingerbread, we recommend using the onStop method of each Activity in your app. For services (or other Contexts), ensure that onStop is called in each instrumented Service. Make sure to match up a call to onEndSession for each call of onStartSession, passing in the same Context object that was used to call onStartSession. Do not pass in the global Application context.
As long as there is any Context that has called onStartSession() but not onEndSession(), the session will be continued. Also, if a new Context calls onStartSession() within 10 seconds of the last Context calling onEndSession(), then the session will be resumed, instead of a new session being created. Session length, usage frequency, events and errors will continue to be tracked as part of the same session. This ensures that as a user transitions from one Activity to another in your app that they will not have a separate session tracked for each Activity, but will have a single session that spans many activities. If you want to track Activity usage, Flurry recommends using logEvent(), as described in the Custom Events section.
If you wish to change the window during which a session can be resumed, call FlurryAgent.setContinueSessionMillis(long milliseconds) before the call to FlurryAgent.init().
The Flurry SDK automatically transfers the data captured during the session once the SDK determines the session completed. In case the device is not connected, the data is saved on the device and transferred once the device is connected again. The SDK manages the entire process. Currently, there is no way for the app to schedule the data transfer.
You’re done! That’s all you need to do to begin receiving basic metric
data.
I'm trying to use Google's App Invites API with my Android app and according to their guide, I need to put a config file that is generated from the developer console in the app/ directory of the project. My app has multiple build flavors, one for production, qa, and debug. I don't know how this works (since it is a pluging) with multiple build flavors and am hoping that someone can shed some light on this issue.
I investigated a bit regarding the google-services plugin and json and found the sources to this plugin.
First things first:
The gradle-plugin google-services that is referenced by classpath and with apply is a build-time plugin only! So it only influences the build-process of your app, but not the runtime-process!
This plugin is only meant as a quickstart-helper to integrating Google-services quickly in your app. Obviously, the process is somewhat convoluted and not documented, so Google should have made it clear what this process does.
In fact, I found the source code for the plugin version com.google.gms:google-services:1.4.0-beta3 and didnt find any specific reference in it regarding appinvites nor did I find any Google API for App Invites! (But maybe it just uses a generic API project with its project id, I didnt try this)
What it does:
The google-services gradle-plugin looks for the mentioned google-services.json file in your app-module. Then it looks for configured settings like project-id's and tracking-id's and such, generated by the Google API developer console into the google-services.json file.
From the settings it found, Android resource values are generated into the following path:
$project.buildDir/generated/res/google-services/$variant.dirName/values/values.xml
For example for a debug-build of your app:
app/generated/res/google-services/debug/values/values.xml
E.g. if you followed the GCM tutorial, the JSON file would include the API project's id as the following android-resource:
<string name="gcm_defaultSenderId">project-id</string>
So this plugin and JSON file are not essential to running or publishing your app, it is just a quickstart helper to generate some basic android-resource files for easier integration of specific Google API features.
Notice in the source code referenced below that the google-services plugin always generates those android-resources for every app-variant that is defined in your app/build.gradle.
If you don't want that, you should use those generated resources in the app-variants you want, and delete the others. Don't forget to remove the google-services plugin apply from app/build.gradle, or else it will be regenerated for all app-variants.
What it does not:
This plugin and JSON-file do NOT directly influence the inner workings of said Google-features for your app!
If you already have followed older tutorials on developer.android.com on how to integrate e.g. GCM or Google Analytics, then you don't even need to integrate either the gradle-plugin google-services or the google-services.json file!
Notice about where I found the sources:
After you integrated the google-services gradle-plugin and when sync your project, Gradle automatically downloads the google-services dependency to a path similar to this (on Windows, you might need to look into your home/.gradle for Linux):
C:\Users\user\.gradle\caches\modules-2\files-2.1\com.google.gms\google-services\1.4.0-beta3\f1580f62e3be313eba041ce19b64fd3f44cf8951\google-services-1.4.0-beta3-sources.jar
If you extract this jar-file, you will find two files:
GoogleServicesPlugin.groovy
GoogleServicesTask.java
which contain the plain source code of the gradle-plugin.
GoogleServicesPlugin.groovy
contains the handling of the app-variants and basic definitions of paths etc.
GoogleServicesTask.java
contains the actual task-definition, look for the following method to see what it really does:
#TaskAction
public void action() throws IOException {
checkVersionConflict();
// google-services.json
if (!quickstartFile.isFile()) {
getLogger().warn("File " + quickstartFile.getName() + " is missing from module root folder." +
" The Google Services Plugin cannot function without it.");
// Skip the rest of the actions because it would not make sense if `quickstartFile` is missing.
return;
}
// delete content of outputdir.
deleteFolder(intermediateDir);
if (!intermediateDir.mkdirs()) {
throw new GradleException("Failed to create folder: " + intermediateDir);
}
JsonElement root = new JsonParser().parse(Files.newReader(quickstartFile, Charsets.UTF_8));
if (!root.isJsonObject()) {
throw new GradleException("Malformed root json");
}
JsonObject rootObject = root.getAsJsonObject();
Map<String, String> resValues = new TreeMap<String, String>();
handleProjectNumber(rootObject, resValues);
JsonObject clientObject = getClientForPackageName(rootObject);
if (clientObject != null) {
handleAnalytics(clientObject, resValues);
handleAdsService(clientObject, resValues);
handleGoogleAppId(clientObject, resValues);
} else {
getLogger().warn("No matching client found for package name '" + packageName + "'");
}
// write the values file.
File values = new File(intermediateDir, "values");
if (!values.exists() && !values.mkdirs()) {
throw new GradleException("Failed to create folder: " + values);
}
Files.write(getValuesContent(resValues), new File(values, "values.xml"), Charsets.UTF_8);
}
So if the Google-docs don’t say which resources are needed for specific Google-features, I would suggest to generate the JSON-file for each relevant buildtype/flavor, see what resources get generated by the plugin and then put those resources manually into their respective src/buildtypeORflavor/res directories.
Delete the references to google-services plugin and the JSON-file after that, and you are done.
According to the Google services gradle plugin documentation, the plugin supports different google-services.json per buildType, but not per flavor
[...] as of version 2.0.0-alpha3 of the plugin support was added for
build types, which would make the following directory structure valid:
app/src/
main/google-services.json
dogfood/google-services.json
mytype1/google-services.json
However, it's not working for me. I'm using 2.0.0-alpha9 and Gradle still complains that it can't find a google-services.json file in root folder
Error:Execution failed for task
':app:processProdReleaseGoogleServices'.
File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.
I've filed a bug: https://code.google.com/p/android/issues/detail?id=200116