Google Cloud Endpoint error: package MyApi does not exist - android

I'm getting this error: package MyApi does not exist message when I run MainActivity. There is similar post here in StackOverFlow, but the solution doesn't work for me.
There is not a logcat stacktrace. What happens is that myApi which is the name of the API inside a class in Google Cloud Module backend is not being recognized and I really don't know why.
Class where my Api is located (module backend)
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.joketellingapp.lacourt.jokesource.JokeSource;
import javax.inject.Named;
/** An endpoint class we are exposing */
#Api(
name = "myApi",
version = "v1",
namespace = #ApiNamespace(
ownerDomain = "backend.builditbigger.gradle.udacity.com",
ownerName = "backend.builditbigger.gradle.udacity.com",
packagePath = ""
)
)
public class MyEndpoint {
#ApiMethod(name = "sayHi")
public MyBean sayHi() {
MyBean response = new MyBean();
response.setData(new JokeSource().getJoke());
return response;
}
}
Class from which i'm trying to access the API (module app)
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v4.util.Pair;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
import com.joketellingapp.lacourt.displayjoke.DisplayJoke;
import com.udacity.gradle.builditbigger.backend.myApi.MyApi;
import java.io.IOException;
class EndpointsAsyncTask extends AsyncTask<Pair<Context, String>, Void, String> {
private static MyApi myApiService = null;
private Context context;
#Override
protected String doInBackground(Pair<Context, String>... params) {
if(myApiService == null) { // Only do this once
MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - turn off compression when running against local devappserver
.setRootUrl("http://10.0.2.2:8888/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end options for devappserver
myApiService = builder.build();
}
context = params[0].first;
// String name = params[0].second;
try {
return myApiService.sayHi().execute().getData();
} catch (IOException e) {
return e.getMessage();
}
}
#Override
protected void onPostExecute(String result) {
// Toast.makeText(context, result, Toast.LENGTH_LONG).show();
Intent intent = new Intent(context, DisplayJoke.class);
intent.putExtra(DisplayJoke.JOKE_KEY, result);
context.startActivity(intent);
}
}
Build.gradle file (Module App)
apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
}
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.joketellingapp.lacourt.jokeapp"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation project(path: ':backend', configuration: 'endpoints')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
implementation 'com.google.code.findbugs:jsr305:3.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api project(':jokeSource')
api project(':displayjoke')
api project(path: ':backend', configuration: 'endpoints')
// api project(path: ':backend')
}
Build.gradle file (Module Backend)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
}
}
repositories {
jcenter()
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
appengine.run.port = 8888
dependencies {
implementation 'com.google.endpoints:endpoints-framework:2.0.9'
implementation 'javax.inject:javax.inject:1'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
compile project(path: ':jokeSource')
}
Top level Build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.guava:guava:22.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir;
}

According to the new plugin docs, it should be endpointsServer project(path: ":server", configuration: "endpoints").

Related

Cannot resolve symbol 'FirebaseListAdapter'

Found a problem while trying to make FirebaseListAdapter for my ListView, which I want to populate from Firebase Real-time Database.
Android Studio says Cannot resolve symbol 'FirebaseListAdapter', when im focusing FirebaseListAdapter<Trick> adapter = new FirebaseListAdapter<Trick>(options){}. Same with FirebaseListOptions<Trick> options = new FirebaseListOptions.Builder<Trick>(){}
Made all changes from a dublicated question, including updating build.gradle, but nothing helps
My project's build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app's build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "cz.zelgadiss.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.GwonHyeok:StickySwitch:0.0.15'
implementation 'com.github.medyo:fancybuttons:1.9.1'
}
My code:
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class EncyActivity extends AppCompatActivity {
ListView list_View;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ency);
Query query = FirebaseDatabase.getInstance().getReference().child("Tricks");
list_View = (ListView) findViewById(R.id.listview);
FirebaseListOptions<Trick> options = new FirebaseListOptions.Builder<Trick>()
.setLayout(R.layout.trick)
.setQuery(query, Trick.class)
.build();
FirebaseListAdapter<Trick> adapter = new FirebaseListAdapter<Trick>(options) {
#Override
protected void populateView(View v, Object model, int position) {
Trick trick = (Trick) model;
TextView name = v.findViewById(R.id.name);
TextView description = v.findViewById(R.id.description);
name.setText(trick.getName().toString());
description.setText(trick.getDescription().toString());
}
};
list_View.setAdapter(adapter);
}
#Override
protected void onStart(){
super.onStart();
adapter.startListening();
}
#Override
protected void onStop(){
super.onStop();
adapter.stopListening();
}
}
In order to use FirebaseListAdapter you will need to import Firebase UI
https://github.com/firebase/FirebaseUI-Android
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:4.3.2'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:4.3.2'
Also check this
https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-the-firebaserecycleradapter

Add a user to a firebase group

So I tried adding a user to a firebase group to be able to send data notification to multiple user on a simple app that show the notification when it receives it.
My problem is that following the firebase documentation I tried adding the following line to my mainactivity.java
FirebaseMessaging.getInstance().subscribeToTopic("weather")
But android studio told me that the .getInstance couldn't be called/"Cannot resolve symbol 'getInstance'é it so I don't know what to do to make it work
edit:
The app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.shayru.myapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.6'
}
The Project build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and if needed this is what the mainactivity does :
package com.shayru.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.firebase.messaging.FirebaseMessaging;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
FirebaseMessaging.getInstance().subscribeToTopic("News");
}
The problem is not with Firebase, rather its with your code. Subscribe to the topic in your onCreate() method, not outside a method.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseMessaging.getInstance().subscribeToTopic("News");
}

Message sent by Firebase not displayed in logcat

I'm a beginner in Android, and I'm trying to send a message with Firebase, but when I send it nothing is displayed in the logcat while my emulator is running and I sent the message.
My service :
package com.example.tibdev.notiffirebase;
import android.app.Service;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
//récupération du message
String message = remoteMessage.getNotification().getBody();
Log.d("FireBaseMessage", "Notfication : " + message);
}
}
My graddle file app :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.tibdev.notiffirebase"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
}
My gradle file build :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've been trying to debug this for a day, but nothing happens, even if I follow some tutorials

How to set description in MPAndroidChart?

I'm a new MPAndroidChart user.
The examples I have found on-line and the Wiki here all give the setDescription() prototype as:
setDescription(String desc)`
However, mChart.setDescription(""); does not compile for me and AndroidStudio->Go To Declaration tells me the declaration for setDescription defined in Chart.java is :
public void setDescription(Description desc) {
this.mDescription = desc;
}
And the Description constructor in Description.java does not take a String.
How do I set the description (or at least turn it off)? Am I pointing to the wrong libraries?
Here is my app's gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And, the module gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.android.nbmc_hbmc"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'pub.devrel:easypermissions:0.2.1'
testCompile 'junit:junit:4.12'
}
And this is my chart code. It compiles and shows the chart but it has the Description Label "Description Label" that I can't change or turn off.
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import java.util.ArrayList;
import java.util.List;
import static com.example.android.nbmc_hbmc.R.id.chart;
public class NbmcEcgGraphActivity extends Activity {
private RelativeLayout mainLayout;
private LineChart mChart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ecggraph);
mainLayout = (RelativeLayout) findViewById(R.id.activity_ecggraph);
// Create new line chart
LineChart mChart = (LineChart) findViewById(chart);
mChart.setDescription(new Description());
mChart.setNoDataText("No Data Yet");
It looks like the wiki is out of date!
The correct syntax in MPAndroidChart 3.0.1 is
mChart.getDescription().setText("Description of my chart");
Reference: javadoc

Kotlin Dagger2 cannot find symbol ApplicationModule_ProvideApplicationFactory

I'm trying to use Dagger2 with Kotlin but today trying to compile got this error:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Error:(5, 43) error: cannot find symbol class ApplicationModule_ProvideApplicationFactory
(App) Build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.ilyarb.geotags"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
dexOptions {
javaMaxHeapSize "2048M"
}
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
final SUPPORT_LIBRARY_VERSION = "23.3.0"
final PLAY_SERVICES_VERSION = "8.4.0"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
// Dagger 2
compile 'com.google.dagger:dagger:2.0.2'
kapt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile "com.google.android.gms:play-services-maps:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-location:$PLAY_SERVICES_VERSION"
compile 'com.jakewharton.timber:timber:4.1.0'
compile 'com.jakewharton.byteunits:byteunits:0.9.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
testCompile 'junit:junit:4.12'
}
repositories {
mavenCentral()
}
buildscript {
ext.kotlin_version = '1.0.1-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
root build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application class
package com.ilyarb.geotags
import android.app.Application
import com.google.android.gms.common.api.GoogleApiClient
import com.ilyarb.geotags.injection.component.ApplicationComponent
import com.ilyarb.geotags.injection.component.DaggerApplicationComponent
import com.ilyarb.geotags.injection.module.ApplicationModule
import com.squareup.leakcanary.LeakCanary
import timber.log.Timber
import javax.inject.Inject
class GeotagApp : Application() {
#Inject lateinit var mGoogleApiClient: GoogleApiClient
companion object {
#JvmStatic lateinit var mApplicationComponent: ApplicationComponent
}
override fun onCreate() {
super.onCreate()
LeakCanary.install(this)
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(ApplicationModule(this))
.build()
mApplicationComponent.inject(this)
}
}
Application Component
package com.ilyarb.geotags.injection.component
import android.app.Application
import com.ilyarb.geotags.injection.module.ApplicationModule
import dagger.Component
import javax.inject.Singleton
#Singleton
#Component(modules = arrayOf(ApplicationModule::class))
interface ApplicationComponent {
fun inject(application: Application)
}
Application Module
package com.ilyarb.geotags.injection.module
import android.app.Application
import com.google.android.gms.common.api.GoogleApiClient
import com.google.android.gms.location.LocationServices
import dagger.Module
import dagger.Provides
import javax.inject.Singleton
#Module
class ApplicationModule(private val mApplication: Application) {
#Provides
#Singleton
fun provideGoogleApiClient() : GoogleApiClient {
return GoogleApiClient.Builder(mApplication)
.addApi(LocationServices.API)
.build()
}
}
It generates DaggerApplicationComponent but when i try to run application it fails with this error.
I've already tried to clean and rebuild the project but it didn't work.
Any help will be greatly appreciated.
Looking through your project I noticed some of your dagger Modules have providing methods with similar names like providesContext(). Dagger 2 (or kapt) may have a problem with it, which results in your error. Please try renaming them, so that all #Provides methods have unique names.
Also annotations have the runtime retention in Kotlin by default, so you don't need to use #Retention(AnnotationRetention.RUNTIME).

Categories

Resources