Debugger doesn't go into MainActivity - android

I got strange problem with white screen and debugger not going into MainActivity. It goes into App class, but doesn't fire the onCreate in MainActivity.
However, if I start my app without debug - just run the app, or build app - it goes into MainActivity fine. I can't find anything specific in my app or any info on what it might be
here's manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.something.something">
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher_new"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
here's App :
public class App extends MultiDexApplication {
private static Api api;
private static Retrofit retrofit;
#Override
public void onCreate() {
super.onCreate();
initRetrofit();
initGlobalVars();
}
private static void initRetrofit() {
if (retrofit == null) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new
HttpLoggingInterceptor.Logger() {
#Override public void log(String message) {
Log.d("MyLog", "message: " + message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(20, TimeUnit.SECONDS)
.writeTimeout(50, TimeUnit.SECONDS)
.readTimeout(50, TimeUnit.SECONDS)
.addInterceptor(logging)
.build();
retrofit = new Retrofit.Builder()
.baseUrl(Setup.URL)
.addConverterFactory(ScalarsConverterFactory.create())
.client(okHttpClient)
.build();
api = retrofit.create(Api.class);
}
}
private void initGlobalVars(){
GlobalVariableKeeper.INSTANCE.init(this);
}
public static Api getApi() {
return api;
}
public static Retrofit getRetrofit(){
return retrofit;
}
}
and gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.something.something"
minSdkVersion 21
targetSdkVersion 28
versionCode 27
versionName "0.35"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
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:27.1.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.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'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.billingclient:billing:1.0'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
}
repositories {
mavenCentral()
}

Related

Android: FirebaseMessaging.getToken() on a null object reference

I'm having problems using onesignal. I tried to use onesignal on another project and it worked but on this project i get error. I guess some libraries are causing this problem.
App Gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'androidx.navigation.safeargs'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
id 'com.onesignal.androidsdk.onesignal-gradle-plugin'}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
buildFeatures {
viewBinding true
}
defaultConfig {
applicationId "com.ersincoskun.focusapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8' }
}
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation files('libs\\YouTubeAndroidPlayerApi.jar')
def nav_version = "2.3.4"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.github.AppIntro:AppIntro:6.1.0'
implementation 'com.akexorcist:round-corner-progress-bar:2.1.1'
implementation 'it.xabaras.android:recyclerview-swipedecorator:1.2.3'
def room_version = "2.3.0"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
def lifecycle_version = "2.3.1"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation 'androidx.activity:activity-ktx:1.3.1'
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
//retrofit
def retrofitVersion = '2.9.0'
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation 'me.tankery.lib:circularSeekBar:1.3.0'
implementation 'com.mikhaellopez:circularprogressbar:3.0.3'
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.4.0-alpha01"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'
implementation 'com.eightbitlab:blurview:1.6.6'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'com.github.MdFarhanRaja:SearchableSpinner:2.0'
implementation platform('com.google.firebase:firebase-bom:28.3.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'
implementation "com.google.firebase:firebase-iid"}
Top Level Gradle
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
jcenter()
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.9'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
def nav_version = "2.3.4"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ersincoskun.focusapp">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission
android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
tools:ignore="ProtectedPermissions" />
<application
android:name=".MyApplicationClass"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="Focused Pupa"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.FocusApp"
android:usesCleartextTraffic="true"
tools:node="replace">
<activity
android:name="com.ersincoskun.focusapp.view.fragments.watchvideo.FullScreenVideoActivity"
android:screenOrientation="sensorLandscape">
</activity>
<service android:name="com.ersincoskun.focusapp.service.SessionService" />
<activity android:name="com.ersincoskun.focusapp.view.activities.NotificationActivity" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="#style/Base.Theme.AppCompat" />
<activity
android:name="com.ersincoskun.focusapp.view.activities.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
<activity
android:name="com.ersincoskun.focusapp.view.activities.RegisterActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity android:name="com.ersincoskun.focusapp.view.activities.IntroActivity" />
<activity
android:name="com.ersincoskun.focusapp.view.activities.SplashScreen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path" />
</provider>
</application>
Application Class
import android.app.Application
import com.onesignal.OneSignal
import androidx.work.Configuration
class MyApplicationClass : Application(),Configuration.Provider {
private val ONESIGNAL_APP_ID = "xxxxxxxxxxxxxxxxxxxxxxx"
override fun onCreate() {
super.onCreate()
// Enable verbose OneSignal logging to debug issues if needed.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)
// OneSignal Initialization
OneSignal.initWithContext(this)
OneSignal.setAppId(ONESIGNAL_APP_ID)
}
override fun getWorkManagerConfiguration() =
Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()
}
Stacktrace
i get these errors what should i do to resolve please help me
my stacktrace
Try initialializing FirebaseApp in your application class to fix this issue.
Application Class
import android.app.Application
import com.onesignal.OneSignal
import androidx.work.Configuration
class MyApplicationClass : Application(),Configuration.Provider {
private val ONESIGNAL_APP_ID = "xxxxxxxxxxxxxxxxxxxxxxx"
override fun onCreate() {
super.onCreate()
// Add this line
FirebaseApp.initializeApp(this)
// Enable verbose OneSignal logging to debug issues if needed.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)
// OneSignal Initialization
OneSignal.initWithContext(this)
OneSignal.setAppId(ONESIGNAL_APP_ID)
}
override fun getWorkManagerConfiguration() =
Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()
}
Hope this helped you out. Happy Coding! :)

unable to write to firebase database

I'm making an app which can write to firebase database on button click.
The app is working on emulator but it's not working on my physical device.
Here's the main activity code:
public class MainActivity extends AppCompatActivity {
private Firebase fled1;
Button on;
Button off;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
on= findViewById(R.id.on);
off= findViewById(R.id.off);
on.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fled1 = new Firebase("https://iotapp-6y3n8.firebaseio.com/");
Firebase fled1Child = fled1.child("S1");
fled1Child.setValue("1");
}
});
off.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fled1 = new Firebase("https://iotapp-6y3n8.firebaseio.com/");
Firebase fled1Child = fled1.child("S1");
fled1Child.setValue("0");
}
});
}
Here's my manifest file I have added all the permissions required:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lalitahuja.iotbutton">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.lalitahuja.iotbutton.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's the build Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.lalitahuja.iotbutton"
minSdkVersion 15
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'])
//noinspection GradleCompatible
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-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
}
apply plugin: 'com.google.gms.google-services'
The error I'm getting:
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 1
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 2
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
W/MessengerIpcClient: Timing out request: 3
W/MessengerIpcClient: Received response for unknown request: 3
E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement
E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.
W/MessengerIpcClient: Received response for unknown request: 1
W/MessengerIpcClient: Received response for unknown request: 2

I/CrashlyticsCore: Crashlytics report upload complete but not show in dashboard

I have problem with Fabric. its a test project for find problem and do everything step by step in fabric documents, but i don't know what is mistake. please help me.
My Gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycompany.testtt"
minSdkVersion 17
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 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
compile('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true;
}
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.testtt">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9fd0b323bad2f5dae063288c94fd3a2317faa104"
/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Main Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
// TODO: Move this to where you establish a user session
logUser();
setContentView(R.layout.activity_main);
}
private void logUser() {
// TODO: Use the current user's information
// You can call any combination of these three methods
Crashlytics.setUserIdentifier("12345");
Crashlytics.setUserEmail("user#fabric.io");
Crashlytics.setUserName("Test User");
}
public void forceCrash(View view) {
throw new RuntimeException("This is a crash");
}
After all, and error and testing, but nothing is still displayed on the dashboard.
I do everything step by step from fabric documents.
I have this problem for a few days, and anyway I've tested it, but I still have not gotten a result and does not display anything in the fabric dashboard. ApiKey is correct and I'm sure of it.
(sorry for English)

SugarORM NullPointerException on save() method

I need a database in my app and I chose SugarORM. But I can't even run a simple example. I have NullPointerException when I use save() method.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.aleksandr.birukov.myapplication"
minSdkVersion 19
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
compile 'com.android.support:support-annotations:27.1.1'
compile 'com.github.satyan:sugar:1.4'
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aleksandr.birukov.myapplication">
<application
android:allowBackup="true"
android:name="com.orm.SugarApp"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="DATABASE"
android:value="notes.db" />
<meta-data
android:name="VERSION"
android:value="1" />
<meta-data
android:name="QUERY_LOG"
android:value="true" />
<meta-data
android:name="DOMAIN_PACKAGE_NAME"
android:value="com.aleksandr.birukov.myapplication" />
</application>
</manifest>
Note.java
package com.aleksandr.birukov.myapplication;
import com.orm.SugarRecord;
public class Note extends SugarRecord {
String title, note;
long time;
public Note() {
}
public Note(String title, String note, long time) {
this.title = title;
this.note = note;
this.time = time;
}
}
MainActivity.java
package com.aleksandr.birukov.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Note note = new Note("title", "desc", 100);
note.save();
}
}
I don't understand what I did wrong?
Make your class extend SugarRecord< Note >

Android + AndroidAnnotations REST API

I am trying to create a simple learning project with AndroidAnnotations, which will work with REST calls. I have followed this tutorial
https://github.com/androidannotations/androidannotations/wiki/Rest-API#rest
but with no luck. Project builds successfully, but at runtime, my #RestService is always null and I cannot get it to work.
Here is how my structure looks like:
build.gradle
apply plugin: 'com.android.application'
def AAVersion = '4.3.0'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile "org.androidannotations:rest-spring-api:$AAVersion"
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
}
Interface (separate file):
#Rest(rootUrl = "https://api.github.com", converters = {StringHttpMessageConverter.class})
public interface GithubClient {
#Get("/search/repositories?q={searchString}")
GitResult getResult(#Path String searchString);
}
MainActivity:
public class MainActivity extends AppCompatActivity {
#RestService
GithubClient restClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Click(R.id.btn_Request)
void requestCall(){
searchAsync();
}
#Background
void searchAsync(){
try {
GitResult result = restClient.getResult("angular");
} catch (RestClientException e){
Log.e("Rest error",e.toString());
}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.githubbrowser">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity_">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Am I missing any package, or what am I doing wrong here? Any help or recommendations would be highly appreciated.
So the problem was that I was missing the following dependencies under build.gradle:
compile "org.androidannotations:rest-spring:$AAVersion"
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
Just to update this thread, currently compile is obsolete therefore I use this
// android annotation
implementation "org.androidannotations:androidannotations-api:4.5.2"
annotationProcessor "org.androidannotations:androidannotations:4.5.2"
implementation "org.androidannotations:rest-spring-api:4.5.2"
annotationProcessor "org.androidannotations:rest-spring:4.5.2"
implementation "com.fasterxml.jackson.core:jackson-core:2.9.7"
implementation "org.springframework.android:spring-android-rest-template:2.0.0.M3"

Categories

Resources