There is no problem with importing, but problems come with activity. When I change extends fromActivity to ActionBarActivity I get a lot of problems...
Why with extends ActionBarActivity I have no more methods like findViewById() or getFragmentManager(), etc.. How can I fix it?
Add the following lines into your build.gradle.
dependencies {
// other dependencies
compile "com.android.support:appcompat-v7:18.0.+"
}
Your build.gradle file should look similar to below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Related
I've got an error while building my project. This is my error message: cannot access MenuHost
class file for androidx.core.view.MenuHost not found.
I didn't find any solution for this problem. I would be very happy if you could help me.
I've got this error for an empty Activity:
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class CallActivity extends AppCompatActivity {
/* Access modifiers changed, original: protected */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.activity_call);
}
}
This is my build.gradle (app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.ghostcontact"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core:1.6.0'
force 'androidx.core:core-ktx:1.6.0'
}
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-storage:20.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.hbb20:ccp:2.3.1'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.firebase:firebase-core:20.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.2.4'
implementation 'com.google.firebase:firebase-analytics:20.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'commons-validator:commons-validator:1.6'
implementation 'com.airbnb.android:lottie:3.4.0'
//OTP PIN View Design
implementation 'com.chaos.view:pinview:1.4.3'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.core:core:1.6.0'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
implementation 'androidx.activity:activity-ktx:1.4.0'
}
And my build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven{url 'https://maven.fabric.io/public'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.google.gms:google-services:4.3.10'
// 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'}
maven{url 'https://dl.bintray.com/tapsellorg/maven'}
maven{url 'https://maven.google.com/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Had the same problem. Fixed the issue by removing this lines:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.6.0' }
}
under defaultConfig of build.gradle(:app)
I also do not know the source/reason behind the error as well.
In the build.gradle i changed this:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.6.0' }
}
to this:
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.7.0' }
}
and this worked for me.
MenuHost was added in androidx.core:core:1.7.0 and above.
https://developer.android.com/jetpack/androidx/releases/core#1.7.0-alpha02
Just upgrade your dependencies.
Just add in you dependencies:
implementation 'androidx.core:core:{latest version}' // 1.7.0 or above
I had exact same situation - changing "extends AppCompatActivity" to "extends Activity" fixed the issue.
Edit: I don't know the source/reason behind that error, sadly...
For me it worked when I manually cast it to MenuHost:
private lateinit var menuHost: MenuHost
override fun onAttach(context: Context) {
super.onAttach(context)
menuHost = (requireActivity() as MenuHost)
}
If this does not work, manually specifying the module you want to use should fix it. In the project build.gradle file you have to add this:
allprojects {
...
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("androidx.activity:activity:1.0.0") using module("androidx.activity:activity:$libVersions.activity")
substitute module("androidx.fragment:fragment:1.1.0") using module("androidx.fragment:fragment:$libVersions.fragment")
substitute module("androidx.core:core:1.2.0") using module("androidx.core:core:$libVersions.core")
substitute module("androidx.core:core-ktx:1.2.0") using module("androidx.core:core-ktx:$libVersions.core")
}
}
}
}
(Double check what version you have in your project that affects you, in my case I noticed 1.00 for activity, 1.1.0 for fragment and 1.2.0 for core - they could be different in your case, you need to check the list of dependencies of your project)
And you can use it directly as:
private lateinit var menuHost: MenuHost
override fun onAttach(context: Context) {
super.onAttach(context)
menuHost = requireActivity()
}
I was setting up a java/kotlin library for my android project in which i was creating a data class (model) with moshi converter. But the issue is the annotation #JsonClass and at other places i am getting this error
Cannot access class 'java.lang.String'. Check your module classpath for missing or conflicting dependencies
The Data class
The data class image
The error shown by IDE
The library gradle code
plugins {
id 'java-library'
id 'kotlin'
id 'kotlin-kapt'
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
implementation "com.squareup.moshi:moshi:1.12.0"
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0"
}
And the app level build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.1.0-alpha01'
kotlin_version = '1.5.21'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app level gradle code
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.composeappname"
minSdk 23
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.tests.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation project(":libmynetworklibrary")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.tests.ext:junit:1.1.3'
androidTestImplementation 'androidx.tests.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-tests-junit4:$compose_version"
}
Error Message:- Could not find method implementation() for arguments [directory
'libs'] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Code
apply plugin: 'com.android.application'
ext {
supportVersion='27.1.1'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.eassycars.www.dlservices"
minSdkVersion 17
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'
}
}
buildscript {
repositories {
jcenter()
}
configure(':app') {
dependencies {
classpath 'com.android.tools.build.gradle:4.8.1'
implementation fileTree (include: ['*.jar'], dir: 'libs')
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler :$supportVersion"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation 'com.orhanobut:hawk:2.0.1'
classpath 'com.google.gms:google-services:3.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
}}
}
}
I updated the "distributionUrl in my "gradle/wrapper/gradle-wrapper.properties" file to match the current gradle version.
I also updated the classpath in my top level build.gradle file to match the gradle API level.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
Re-synced and then it built OK.
Because you have incorrect block in your build.gradle. Looks like you're mixing top level build.gradle and module build.gradle. Your app module build.gradle should be something like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
}
buildTypes {
release {
...
}
}
..
}
dependencies {
...
}
please visit Configure your build for details.
Remove the space between version:
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler:$supportVersion"
Also, please move the dependencies block out of the android block:
android {
...
}
...
dependencies{
...
}
I'm pretty sure its a built in feature but I cant find anything when searching or in the docs. Is there a flag for building with multidex enabled?
On another note:
Any way to see which libraries are messing with your method count? Hitting the 64k limit came as quite a surprise.
For RN 0.59+ and using Gradle 3.4.1, none of the answers here had the complete solution. I did the following and it worked:
In android/app/build.gradle, update the dependency block:
dependencies {
// ... your other dependencies
// Multidex
implementation 'com.android.support:multidex:1.0.3'
}
And also update the defaultConfig in the android block:
defaultConfig {
// ... your `applicationId`, etc.
multiDexEnabled true
}
In MainApplication.java, replace
import android.app.Application;
at the top with
import android.support.multidex.MultiDexApplication;
OR if you're on RN 0.60+ or have manually upgraded to AndroidX then use this instead:
import androidx.multidex.MultiDexApplication;
Still in MainApplication.java, replace
public class MainApplication extends Application implements ReactApplication {
with
public class MainApplication extends MultiDexApplication implements ReactApplication {
Found the answer somewhere else. It's no different than enabling it for any regular Android project.
android {
....
defaultConfig {
...
multiDexEnabled true
}
As for method count, this site does the trick: http://inloop.github.io/apk-method-count/
android/app/build.gradle
android {
....
defaultConfig {
...
multiDexEnabled true
}
If you are using Multidex, your Application should extends MultiDexApplication instead of Application.
MyApplication.java
import android.support.multidex.MultiDexApplication;
public class MyApplication extends MultiDexApplication{
...
}
Since Application must extend ReactApplication, I used a similar approach to the one suggested here which is documented in point 2 in the Android Developer reference on multidex to attach to the base context:
app/build.gradle
android {
compileSdkVersion projectCompileSdkVersion // Or your version
defaultConfig {
minSdkVersion projectMinSdkVersion // Or your version
targetSdkVersion projectTargetSdkVersion // Or your version
multiDexEnabled true // *
}
dexOptions {
jumboMode true // *
}
}
dependencies {
compile 'com.android.support:multidex:1.0.3' // https://mvnrepository.com/artifact/com.android.support/multidex
}
MainApplication.java
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
https://developer.android.com/studio/build/multidex
Step:1
Open the /android/app/build.gradle
android {
...
defaultConfig {
...
multiDexEnabled true <-- ADD THIS LINE
}
}
Step:2
In the same file find dependencies
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1' <-- ADD THIS LINE
...
}
Note: To know latest version for multidex Multidex Latest Version
Step:3
Open the MainApplication.java file under
android/app/src/main/java/.../MainApplication.java
Add the multidex Import
// ... all your other imports here
import androidx.multidex.MultiDexApplication; <-- ADD THIS LINE
Our class definition needs extends MultiDexApplication like below
Beofre (In my case)
public class MainApplication extends Application implements ReactApplication {
After
public class MainApplication extends MultiDexApplication implements ReactApplication {
Replace Application with MultiDexApplication
Spet:4 (Optional)
clean the project
Reference How To Enable Multidex in Android
Hope this helps ;)
As soon as I try to get my object from Realm database, the app crashed and I get this error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.repdev.realtimedelijn/com.repdev.realtimedelijn.activity.MainActivity}:
java.lang.IllegalArgumentException: Haltes is not part of the schema for this Realm
This is my Activity were it happens
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main);
Context context = this;
View view = this.getWindow().getDecorView();
realm = Realm.getInstance(getRealmConfiguration());
RealmResults<Haltes> haltes = realm
.where(Haltes.class)
.findAll();
HaltesRecyclerViewAdapter haltesRecyclerViewAdapter =
new HaltesRecyclerViewAdapter(this, haltes, true, true);
RealmRecyclerView realmRecyclerView =
(RealmRecyclerView) findViewById(R.id.realm_recycler_view);
realmRecyclerView.setAdapter(haltesRecyclerViewAdapter);
}
and here is the model
Someone an idea how to fix it?
public class Haltes implements RealmModel {
#PrimaryKey
private long id;
private String halteNaam;
private String halteNummer;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getHalteNaam() {
return halteNaam;
}
public void setHalteNaam(String halteNaam) {
this.halteNaam = halteNaam;
}
public String getHalteNummer() {
return halteNummer;
}
public void setHalteNummer(String halteNummer) {
this.halteNummer = halteNummer;
}
}
My problem was solved by declaring apply plugin: 'realm-android' after all other plugins.
App level Gradle
apply plugin: 'android-apt'
apply plugin: 'realm-android'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
had the same problem while using it along side with retrolambda and android-apt.
changing the order of plugins in app level build.gradle file worked for me :
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
Github issue : https://github.com/realm/realm-java/issues/3783#issuecomment-260578984
In my case I was need to paste kotlin-kapt to app.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' <<<<<<<<<<the 1st row<<<<<<<<<
apply plugin: 'realm-android' <<<<<the second row<<<<<
I spent 6 hours to solve this problem. And now it works.
And how was written above - realm-android should be added to the end of all plugins!
Are you using the #RealmClass annotation?
If you are using annotations, make sure you have annotation processing enabled in your Android studio settings.
Try this: Android Studio -> Build -> Rebuild & Clean Project
I believe this has to do with adding a new Realm Model class after some models were already added. try un installing the application and run again or migrate your schema.
Does your Haltes class extends RealmObject?
Make it like this:
public class Haltes extends RealmObject
or
#RealmClass
public class Haltes implements RealmModel
You haven't added Realm to your build.gradle file: https://bitbucket.org/repdev/realtimedelijnandroid/src/77c531768dc1250b4d5b5c6c7fd4e6100764177d/build.gradle?at=master&fileviewer=file-view-default
See how here: https://realm.io/docs/java/latest/#installation
Your top level build.gradle file should have this
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.0.1"
}
}
Your app level build.gradle file should have this at the top:
apply plugin: 'realm-android'
For those of you who use a mixture of Kotlin in your codebase, then this problem will be solved by applying kotlin-kapt before realm-android.
That is:
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
Source:
https://github.com/realm/realm-java/issues/5697
I got this exception when using a library project with my app project and realm plugin is only applied to the library project.
When I added realm plugin `apply plugin: 'realm-android' to the app project ,the exception gone.
Make sure realm plugin added to every gradle project that uses realm.