Some error(s) occurred while processing annotations - android

When I add the code int activity
#Inject
lateinit var mCommonService:CommonService
The error comes
e: Error: Can't access Nullable
e: Can't find javax.annotation.Nullable
e: For details, please refer to the following stacktrace.
w: Warning: These options aren't used by any annotation processors:'[kapt.kotlin.generated]'
e: Some error(s) occurred while processing annotations. Please see the error messages above.
this is my module build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.google.dagger:dagger:2.11'
kapt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
// compile 'com.android.support:support-annotations:26.0.0-alpha1'
kapt "com.android.databinding:compiler:$rootProject.ext.gradle_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
This is my component
#ActivityScope
#Component(modules = arrayOf(CommonModule::class),dependencies = arrayOf(AppComponent::class))
interface CommonComponent {
fun inject(activity: MainActivity)
}
This is my module
#Module
class CommonModule {
#Singleton #Provides fun provideCommonService(retrofit: Retrofit): CommonService {
return retrofit.create(CommonService::class.java)
}
}
And this is my activity
#Inject
lateinit var mCommonService:CommonService// when i inject this,the error comes
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getViewDataBinding(R.layout.activity_main)
DaggerCommonComponent.builder()
.appComponent(appComponent)
.commonModule(CommonModule())
.build()
.inject(this)
}
If I delete the inject code the program run correctly, I try add #JvmWildcard at CommomService #provides return type, but it still doesn't work

Related

java.lang.NoSuchMethodError: No static method

I just start using RxJava in my projects, i have got this error :
java.lang.NoSuchMethodError: No static method getService()Lcom/app/seddik/yomii/api/GalleryPhotosService;
In this class the error has occured, and says :
No static method getService()Lcom/app/seddik/yomii/api/GalleryPhotosService; in class Lcom/app/seddik/yomii/api/GalleryPhotosService; or its super classes (declaration of 'com.app.seddik.yomii.api.GalleryPhotosService' appears in /data/app/com.app.seddik.yomii-2/base.apk:classes27.dex)
at com.app.seddik.yomii.data.datasource.GalleryPhotosDataSource.(GalleryPhotosDataSource.java:40)
public class GalleryPhotosDataSource extends ItemKeyedDataSource<Integer, GalleryPhotosItems> {
private GalleryPhotosService galleryPhotosService;
private CompositeDisposable compositeDisposable;
private MutableLiveData<NetworkState> networkState = new MutableLiveData<>();
private MutableLiveData<NetworkState> initialLoad = new MutableLiveData<>();
/**
* Keep Completable reference for the retry event
*/
private Completable retryCompletable;
GalleryPhotosDataSource(CompositeDisposable compositeDisposable) {
this.galleryPhotosService = GalleryPhotosService.getService();
this.compositeDisposable = compositeDisposable;
}
....
The error appear in this line :
this.galleryPhotosService = GalleryPhotosService.getService();
My gradle dependencies :
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "com.app.seddik.yomii"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:2.5.1'
// Support libraries
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.1.0'
compile 'com.android.support:support-v4:27.1.0'
// Retrofit
compile 'com.squareup.retrofit2:retrofit:2.4.0'
compile 'com.squareup.retrofit2:converter-gson:2.4.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
// Glide
compile 'com.github.bumptech.glide:glide:4.6.1'
compile 'com.github.bumptech.glide:compiler:4.6.1'
compile 'com.github.bumptech.glide:okhttp3-integration:4.6.1'
compile 'com.squareup.picasso:picasso:2.5.2'
// Others
compile 'com.github.chrisbanes:PhotoView:2.1.3'
compile 'com.github.varunest:sparkbutton:1.0.5'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.andkulikov:transitionseverywhere:1.7.8'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
compile 'com.zhihu.android:matisse:0.4.3'
compile 'com.seatgeek:placesautocomplete:0.3-SNAPSHOT'
compile 'id.zelory:compressor:2.1.0'
compile 'org.greenrobot:eventbus:3.1.1'
compile 'com.github.florent37:shapeofview:1.1.2'
// Firebase Messaging
compile 'com.google.firebase:firebase-messaging:17.1.0'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.android.support:multidex:1.0.1'
//Google services
compile 'com.google.android.gms:play-services-location:15.0.0'
compile 'com.google.android.gms:play-services-places:15.0.0'
// find bugs
compile 'com.google.code.findbugs:jsr305:2.0.1'
// Timber for logging
compile 'com.jakewharton.timber:timber:4.6.1'
//Architecture Components
compile "android.arch.lifecycle:extensions:1.1.0"
//Paging
compile "android.arch.paging:runtime:1.0.1"
//Rx
compile 'io.reactivex.rxjava2:rxjava:2.2.0'
compile 'io.reactivex.rxjava2:rxandroid:2.1.0'
testCompile 'junit:junit:4.12'
}apply plugin: 'com.google.gms.google-services'
This my interface Retrofit Service :
public interface GalleryPhotosService {
// Retrofit services
static GalleryPhotosService getService() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(AppConfig.URL_UPLOAD_PHOTOS)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(GalleryPhotosService.class);
}}

ViroCore: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/vr/ndk/base/GvrLayout;

I have downloaded ViroCore lib the latest version (virocore-release-v_1_7_2.aar), then I added dependencies below to my build.gradle file
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.0.0'
implementation 'com.google.android.exoplayer:exoplayer:r2.2.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation (name:'virocore-release-v_1_7_2', ext: 'aar')
implementation 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
implementation 'com.amazonaws:aws-android-sdk-core:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.+'
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.+'}
and then wrote to my ViroActivity code below:
private ViroView createGVRView() {
return new ViroViewGVR(this, new ViroViewGVR.StartupListener() {
#Override
public void onSuccess() {
onRendererStart();
}
#Override
public void onFailure(ViroViewGVR.StartupError error, String errorMessage) {
onRendererFailed(error.toString(), errorMessage);
}
}, new Runnable() {
#Override
public void run() {
}
});
}
But when run the app, I always see next Exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.virosample.gvr.ovr, PID: 17304
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/vr/ndk/base/GvrLayout;
at com.viro.core.ViroViewGVR.init(ViroViewGVR.java:287)
at com.viro.core.ViroViewGVR.<init>(ViroViewGVR.java:211)
at com.example.panorama.ui.view.ViroActivityVR.createGVRView(ViroActivityVR.java:104)
at com.example.panorama.ui.view.ViroActivityVR.onCreate(ViroActivityVR.java:90)
...
Anyone knows how to resolve this exception?
I solved this issue. I added to my dependency just viro library, but I must add additionally both sdk-common.aar and core.aar which you can download at the official virocore site.

Error:Gradle: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'

I build app using Kotlin with MVVM architecture, and now i write Unit Test for my ViewModel, just use JUnit and Mockito
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.1.0'
kapt 'com.github.bumptech.glide:compiler:4.1.0'
kapt 'com.android.databinding:compiler:3.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation 'org.mockito:mockito-core:2.12.0'
}
But, when i try to run test, i got this following error :
Error:Gradle: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Landroid/support/compat/R$bool;
Here is my test class :
#RunWith(MockitoJUnitRunner::class)
class RegistrationFragmentViewModelTest {
var mViewModel: RegistrationFragmentViewModel? = null
#Mock var mContext: Context? = null
#Mock var mView: RegistrationView? = null
#Before
fun setUp() {
mViewModel = RegistrationFragmentViewModel(mContext!!, mView!!)
}
#Test
fun AfterInput_InvalidFirstName_ShowFirstNameError() {
// Given
val firstName = "fa"
val email = "fanjavaid#gmail.com"
val password = "demo"
// When
mViewModel?.doRegister()
// Then
verify(mViewModel)?.validateInput()
verify(mView)?.showFirstNameError(mContext?.resources?.getString(R.string.registration_error_email_format)!!)
}
}
I still don't know why. Any ideas?
Thank you?

Fcm token getting null

i have used following dependencies.
it gives me "Default FirebaseApp is not initialized in this process.Make sure to call FirebaseApp.initializeApp(Context) first."
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
/*compile('org.apache.httpcomponents:httpcore:4.4.1') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}*/
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile('com.google.api-client:google-api-client-android:1.22.0')
compile('com.google.apis:google-api-services-script:v1-rev6-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile 'pub.devrel:easypermissions:0.1.5'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'me.spark:submitbutton:1.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
testCompile 'junit:junit:4.12'
compile files('libs/org.apache.http.legacy.jar')
}
This has little to do with your dependencies, you'll need to initialize Firebase before using it in your code.
So at the very beginning (Or at least before you make any references to Firebase) add the following:
FirebaseApp.initializeApp(getContext());
In Your Project gradle file put this dependancy
classpath 'com.google.gms:google-services:3.0.0'
and than your module gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
it Work for me.
Put this line at the bottom of your app build.gradle file (* last statement)
apply plugin: 'com.google.gms.google-services'
and also check if you are using this dependency in upper gradle file
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
//classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
You have to initialize Firebase befor you use it and best place to initialize it in Application Class
public class App extends BaseApplication {
public static App _appContext = null;
public static final String TAG = App.class.getSimpleName();
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
_appContext = this;
Firebase.setAndroidContext(getApplicationContext());
FirebaseApp.initializeApp(getContext());
}
}
And add it to mainifiest file Application Tag like
<application
android:name="your.path.to.App"
.
.>
Than try and let me know
You can try this
Remove:
Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);
And put:
FirebaseDatabase database = FirebaseDatabase.getInstance();

RxAndroid with Retrofit 2.0

I have interface
#GET("/data, 2.5/forecast/daily")
Observable<MultilingualWeather> getWeatherByIdWithMultilingual(
#Query("id") String id,
#Query("lang") String lang,
#Query("appid") String appid);
MainActivity be called up in the following configuration
Retrofit retrofit_weather = new Retrofit.Builder().
baseUrl(BASE_URL).
addConverterFactory(GsonConverterFactory.create()).
addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
build();
GetWeatherForLocation getWeather = retrofit_weather.create(GetWeatherForLocation.class);
Observable<MultilingualWeather> call_observable = getWeather.
getWeatherByIdWithMultilingual(
CITY_ID,
LANG,
KEY
);
subscription = call_observable.subscribe(subscriber);
The following file dependencies
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
}
and after all this takes off exception
FATAL EXCEPTION: main Process: com.example.alex.weatherclient, PID: 16658 java.lang.AbstractMethodError: abstract method "retrofit.CallAdapter retrofit.CallAdapter$Factory.get(java.lang.reflect.Type, java.lang.annotation.Annotation[], retrofit.Retrofit)"
Replace in build.gradle
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
on
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
looks like a typo. Your interface uses getWeatherByIdWithMultilingual and your code uses getWeatherByIdWithMultilingual2

Categories

Resources