problem with adding Google Analytics to flutter app - android-studio

I want to add Google Analytic to my flutter app.
this a walk trough that I fallow (Add Analytics to Your Android App
)
when I do the steps of the linked help, I got error in build process,
and my IDE doesn't resolve these imports:
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
I put here my project files:
MainActivity.java:
package com.example.flutterapp;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
// Obtain the shared Tracker instance.
AnalyticsApplication application = (AnalyticsApplication)
getApplication();
private static Tracker mTracker = application.getDefaultTracker();
mTracker.setScreenName("home");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
AnalyticsApplication.java:
package com.example.flutterapp;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
public class AnalyticsApplication extends Application {
private static GoogleAnalytics sAnalytics;
private static Tracker sTracker;
#Override
public void onCreate() {
super.onCreate();
sAnalytics = GoogleAnalytics.getInstance(this);
}
/**
* Gets the default {#link Tracker} for this {#link Application}.
* #return tracker
*/
synchronized public Tracker getDefaultTracker() {
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
if (sTracker == null) {
sTracker = sAnalytics.newTracker(R.xml.global_tracker);
}
return sTracker;
}
}
the error I get when I build:
...............................
Launching lib\main.dart on SM J320F in debug mode...
Initializing gradle...
[{"event":"app.progress","params":{"appId":"11b94d0e-10f8-4ea3-aa07-9c1df09f1d27","id":"1","progressId":null,"message":"Resolving dependencies..."}}]Resolving dependencies...
Gradle task 'assembleDebug'...
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:22: error: <identifier> expected
mTracker.setScreenName("home");
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:22: error: illegal start of type
mTracker.setScreenName("home");
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: <identifier> expected
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: illegal start of type
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: ')' expected
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: ';' expected
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: invalid method declaration; return type required
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
D:\projects\flutter_test\flutter_app\android\app\src\main\java\com\example\flutterapp\MainActivity.java:23: error: ';' expected
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
^
8 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
Finished with error: Gradle task assembleDebug failed with exit code 1
...............................
how Can I solve this problem?
please help me, thank you.

I think it's because of AndroidX compatibility. You can try to change to older version of dependency. That helped me for some dependencies.

Related

Importing class from the root folder from a class in a package: unable to resolve class

I have the following directory/package structure in my groovy project:
src
+ progressManagers (package)
| |
| + LoadSensitiveProgressManager.groovy
+ TemporaryRegistry.groovy
Contents of TemporaryRegistry.groovy
// here is no package definition set
public class TemporaryRegistry {}
Contents of LoadSensitiveProgressManager.groovy
package progressManagers
// this gets marked red in my IDE (Intellij Idea)
import TemporaryRegistry
class LoadSensitiveProgressManager implements GenericProgressManager {
}
When i run my code in Scriptrunner for Jira Server the class is not found:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/data/atlassian/application-data/jira/scripts/progressManagers/LoadSensitiveProgressManager.groovy: 7: unable to resolve class TemporaryRegistry
# line 7, column 1.
import TemporaryRegistry
^
1 error
Why is that?
I can "import TemporaryRegistry" from every groovy file in the src folder.
Thanks in advance
Jens

Facing error while using image_picker in flutter

Hy, I am new to flutter and while working with an app that uses image_picker to get images from the gallery I was facing this error.
C:\Users\Hrishabh Mishra\Desktop\FDR\Flutter\course\08\mycameraapp>flutter run
Launching lib\main.dart on Redmi Note 5 Pro in debug mode...
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:15: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
^
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:16: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
^
symbol: class ActivityCompat
location: package android.support.v4.app
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:17: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerFileProvider.java:3: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
^
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerFileProvider.java:10: error: cannot find symbol
public class ImagePickerFileProvider extends FileProvider {}
^
symbol: class FileProvider
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerPlugin.java:8: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
^
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:68: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY = 2342;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:69: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA = 2343;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:70: error: cannot find symbol
#VisibleForTesting static final int REQUEST_EXTERNAL_IMAGE_STORAGE_PERMISSION = 2344;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:71: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CAMERA_IMAGE_PERMISSION = 2345;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:72: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_CHOOSE_VIDEO_FROM_GALLERY = 2352;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:73: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA = 2353;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:74: error: cannot find symbol
#VisibleForTesting static final int REQUEST_EXTERNAL_VIDEO_STORAGE_PERMISSION = 2354;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:75: error: cannot find symbol
#VisibleForTesting static final int REQUEST_CAMERA_VIDEO_PERMISSION = 2355;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:77: error: cannot find symbol
#VisibleForTesting final String fileProviderName;
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:164: error: cannot find symbol
#VisibleForTesting
^
symbol: class VisibleForTesting
location: class ImagePickerDelegate
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerPlugin.java:40: error: cannot find symbol
#VisibleForTesting
^
symbol: class VisibleForTesting
location: class ImagePickerPlugin
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:122: error: cannot find symbol
return ActivityCompat.checkSelfPermission(activity, permissionName)
^
symbol: variable ActivityCompat
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:128: error: cannot find symbol
ActivityCompat.requestPermissions(activity, new String[] {permissionName}, requestCode);
^
symbol: variable ActivityCompat
H:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.4.12+1\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java:140: error: cannot find symbol
return FileProvider.getUriForFile(activity, fileProviderName, file);
^
symbol: variable FileProvider
20 errors
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':image_picker:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 28s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 32.5s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin image_picker...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 22.3s
WARNING: The option setting 'android.enableR8=true' is experimental and unsupported.
The current default is 'false'
Consider disabling R8 by removing 'android.enableR8=true' from your gradle.properties before publishing your app.
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'imagepicker'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 16s
The plugin image_picker could not be built due to the issue above.
SDK location not found. Define location with sdk.dir in the local.properties file or
with an ANDROID_HOME environment variable.
Configure the Android SDK first.
Method 1:
Go to Settings
Expand Language & Frameworks
Select Flutter
Enter the flutter sdk path in Flutter SDK Path textbox
Click Ok
Method 2:
Flutter provides a command to update the Android SDK path:
Use flutter config --android-sdk <path-to-your-android-sdk-path>

Decorators plugin missing with polymer-cli

I'm using polymer-cli (v1.9.11) to serve my project while developing it :
polymer-cli serve
But when I use decorators (#customElement) in my js sources like this :
import { LitElement, html, property, customElement } from 'lit-element';
import '#polymer/iron-ajax';
import '#vaadin/vaadin-combo-box';
#customElement('my-element') // HERE
class MyElement extends PolymerElement {
static get properties() {
It raises this error when I request the file :
Error SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (5:0)
at Parser.raise (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:776:15)
at Parser.expectOnePlugin (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:2098:18)
at Parser.parseDecorator (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:4133:10)
at Parser.parseDecorators (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:4115:28)
at Parser.parseStatement (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:3959:12)
at Parser.parseBlockOrModuleBlockBody (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:4513:23)
at Parser.parseBlockBody (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:4500:10)
at Parser.parseTopLevel (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:3938:10)
at Parser.parse (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:5304:17)
at Object.parse (/usr/lib/node_modules/polymer-cli/node_modules/babylon/lib/index.js:10083:24) {
pos: 138,
loc: Position { line: 5, column: 0 },
missingPlugin: [ 'decorators-legacy', 'decorators' ]
}
So I'm wondering where I should declare one of these plugins ?

Getting SparkFlumeProtocol and EventBatch not found errors when building Spark 1.6.2 on CentOS7

I was trying to build Spark 1.6.2 on CentOS7 and ran into the error below:
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/SparkAvroCallbackHandler.scala:45: not found: type SparkFlumeProtocol
[error] val transactionTimeout: Int, val backOffInterval: Int) extends SparkFlumeProtocol with Logging {
[error] ^
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/SparkAvroCallbackHandler.scala:70: not found: type EventBatch
[error] override def getEventBatch(n: Int): EventBatch = {
[error] ^
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/TransactionProcessor.scala:80: not found: type EventBatch
[error] def getEventBatch: EventBatch = {
[error] ^
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/SparkSinkUtils.scala:25: not found: type EventBatch
[error] def isErrorBatch(batch: EventBatch): Boolean = {
[error] ^
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/SparkAvroCallbackHandler.scala:85: not found: type EventBatch
[error] new EventBatch("Spark sink has been stopped!", "", java.util.Collections.emptyList())
[error] ^
[warn] Class org.jboss.netty.channel.ChannelFactory not found - continuing with a stub.
[warn] Class org.jboss.netty.channel.ChannelFactory not found - continuing with a stub.
[warn] Class org.jboss.netty.channel.ChannelPipelineFactory not found - continuing with a stub.
[warn] Class org.jboss.netty.handler.execution.ExecutionHandler not found - continuing with a stub.
[warn] Class org.jboss.netty.channel.ChannelFactory not found - continuing with a stub.
[warn] Class org.jboss.netty.handler.execution.ExecutionHandler not found - continuing with a stub.
[warn] Class org.jboss.netty.channel.group.ChannelGroup not found - continuing with a stub.
[error] /home/pateln16/spark-1.6.2/external/flume-sink/src/main/scala/org/apache/spark/streaming/flume/sink/SparkSink.scala:86: not found: type SparkFlumeProtocol
[error] val responder = new SpecificResponder(classOf[SparkFlumeProtocol], handler.get)
I meet the same problem on Spark 2.0.0. I think the reason is that file 'external\flume-sink\src\main\avro\sparkflume.avdl' is not complied well.
The problem can be resolved by:
Download Apache Avro
http://avro.apache.org/docs/current/gettingstartedjava.html
I downloaded all jar files into folder 'C:\Downloads\avro'.
Go to folder 'external\flume-sink\src\main\avro'
compile sparkflume.avdl to java files
java -jar C:\Downloads\avro\avro-tools-1.8.1.jar idl sparkflume.avdl > sparkflume.avpr
java -jar C:\Downloads\avro\avro-tools-1.8.1.jar compile -string protocol sparkflume.avpr ..\scala
recompile your projects.

How to make a task to call a main class

What I am trying to do is make a task in build.gradle that will execute a main class (class with the main method), but I don't know how.
I made a test project to test how to do that. Here is the file structure layout:
testProject/
build.gradle
src/main/groovy/hello/world/HelloWorld.groovy
Here is the content of build.gradle:
apply plugin: 'groovy'
apply plugin: 'maven'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.0.6'
}
task( hello, dependsOn: jar, type: JavaExec ) {
main = 'hello.world.HelloWorld'
}
Here is the content of HelloWorld.groovy:
package hello.world
class HelloWorld {
public static void main(String[] args) {
println "Hello World!"
}
}
Here is what I get from shell:
testProject>$ gradle hello
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:hello
Error: Could not find or load main class hello.world.HelloWorld
:hello FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':hello'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.232 secs
So, my question is: how can I make gradle hello work? Thank you very much.
After a bit of googling, I found a solution. The only thing I need to change is the task block. The working one is pasted below:
task( hello, dependsOn: jar, type: JavaExec ) {
main = 'hello.world.HelloWorld'
classpath = sourceSets.main.runtimeClasspath
}
There is an application plugin for doing this.
apply plugin: 'application'
mainClassName = 'hello.world.HelloWorld'
And then call
gradle run
Besides adding run task, applying application plugin will also change the behaviour of assemble task. Now it will produce a standalone application that can be run with a shell script.
Consider this build.gradle, which is a simplified version:
apply plugin: 'groovy'
task( hello, type: JavaExec ) {
main = 'hello.world.HelloWorld'
classpath = files('exampleDir/bin','jars/groovy-all-2.0.1.jar')
}
Note the 'classpath' argument to the JavaExec task. This uses subdirectories such as:
exampleDir/src/hello/world/HelloWorld.groovy
exampleDir/bin/hello/world/HelloWorld.class
jars/groovy-all-2.0.1.jar
where:
(a) groovy-all-2.0.1.jar copied from my GROOVY_HOME/embeddable
(b) HelloWorld.groovy is compiled via groovyc and is as follows:
package hello.world
class HelloWorld {
public static void main(String[] args) {
println "Hello World!"
}
}
Just specifying sourceSets.main.runtimeClasspath as a classpath might not be enough. If you see NoClassDefFoundError this might help:
task( hello, dependsOn: jar, type: JavaExec ) {
main = 'hello.world.HelloWorld'
classpath(sourceSets.main.runtimeClasspath, sourceSets.main.compileClasspath)
}

Resources