Android project error - java

I am trying to run an app that has a Google Maps Activity on my phone. My phone's running on Android 4.1.3 and the Minimum SDK for my project is API 15: Android 4.0.3
I just created the project on Android Studio and tried to run it on my phone. But it won't run and I am keep getting this error. Can someone tell me how to solve this?

That error probably means that you are using too much libraries. And because you are trying to use google maps I'm guessing you included everything google.
Try to just use the libraries you need.
For maps use this:
dependencies {
com.google.android.gms:play-services-maps:9.2.1
}
Reading material:
https://developers.google.com/android/guides/setup

You need to configure your gradle for multidex.
Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code snippet:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
See more on same link which you are refering : https://developer.android.com/studio/build/multidex.html#mdex-gradle
You can also see some related question for same error:
How to enable multidexing with the new Android Multidex support library
Android java.exe finished with non-zero exit value 1

Related

targetSDKVersion, minimumSDKVersion, and compileSDKVersion for specific device

I'm programming for one specific device and I'm having trouble understanding how I should be setting minsdkversion, compilesdkversion, and targetsdkversion. I want to get a compiler error when I'm using a library that doesn't exist for API level 25. Here's what I gatherered. Minsdkversion prevents calling API that doesn't exist for API version. Compilesdkversion should always be the latest version. Targetsdkversion is what the app was tested against (don't understand what this means).
minsdkversion-25
compilesdkversion-28 (needed for AndroidX)
targetSDKversion-25
Version settings
Among those version settings, only minSdkVersion takes effect to detect API level error. If you'd like to know details of the version settings, see documentation.
How to let build system report API level error
For release builds, place "lintOptions" in app/build.gradle and mark "NewApi" as "fatal". Then lintVitalRelease gradle task reports error during compilation.
android {
lintOptions {
fatal "NewApi"
}
compileSdkVersion 30
defaultConfig {
minSdkVersion 25
targetSdkVersion 30
:
}
:
}
Checking API level manually
In debug builds, the lintOptions above doesn't have any effects because the lint is not included in debug build tasks (there is no lintVitalDebug gradle task). So rather, after coding, run "code inspection" manually to detect all the NewApi problems in your code. If incompatible API uses found, you'll see "calling new methods on older version" error in the inspection result.

Failed to find style 'coordinatorLayoutStyle' in current theme In Android Studio 3.1

The Android Studio 3.1 layout preview fails to find style 'coordinatorLayoutStyle' in the current theme.
Failed to instantiated one or more classes.
Exception shown are :-
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
This happened due to use of alpha version SDK 28
We need to change the android { ... } in "build.gradle" in app file
compileSdkVersion 28 to compileSdkVersion 27
targetSdkVersion 28 to targetSdkVersion 27
Also, try to change implementations like
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to
implementation 'com.android.support:appcompat-v7:27.1.1'
Hope this works!
For Android Studio v3.1.*, in addition we need change:
implementation 'com.android.support:design:28.0.0-alpha3' to
implementation 'com.android.support:design:27.1.1'
you can fix this issue by adding this script to the app module build.gradle, in the android section
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
This appears to be a bug in the current version of Android Studio (3.1.3) as I was encountering the same thing. I downloaded the beta build from here and opened my existing project and the errors disappeared.
https://developer.android.com/studio/preview/?utm_source=android-studio
Not exactly a fix but hopefully it will get you back up and running.
Update
1. com.android.support:appcompat stable version 28.0.0 is released. So no need to downgrade version. Just use 28.0.0.
def supportVersion = "28.0.0"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
You can ignore design library if you don't need it.
2: You also need to update your compileSdkVersion & targetSdkVersion to remove some gradle warnings.
compileSdkVersion 28
targetSdkVersion 28
Never use alpha versions of any library, because alpha, beta and rc
versions may have bugs. And you don't want to face these types of errors often.
Important Suggestion
I suggest you migrate to androidx because android will not update support library after 28.0.0, all updates will be available to androidx package only. Check related answer.
This is fixed in Android Studio 3.2.
Go to app/res/styles and change the Theme.AppCompat.Light.DarkActionBar for this one Base.Theme.AppCompat.Light.DarkActionBar

Android Studio - java module recompiled on each application recompile

In my Android Studio project, I've added a java module that produces a JAR file which is used by the main module. I understand that Gradle rebuilds all modules on each compile process, but it is clear that it is not needed for java modules if there is no changes since the last build.
So I want to prevent gradle from building my jar file if there is no code changes in the java module, I cannot find such option
Any help is appreciated.
there're two steps to achieve what u want:
Ask the android plugin to pre-dex the libraries.
so you add dexOptions inside the android bracket
android {
dexOptions {
preDexLibraries true
}
}
and the other step is to make your debug build to be minSdkVersion 21, that way the system will build as a multi-dex application so it won't need to merge your dexed library into the APK.
There's a whole section on the dev page about it https://developer.android.com/studio/build/multidex.html#dev-build, but what you want to do is add productFlavors inside the android bracket
android {
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion YOUR_APP_MINIMUM_HERE
}
}
}

Failure [INSTALL_FAILED_OLDER_SDK] android studio error

Android studio shows this Failure [INSTALL_FAILED_OLDER_SDK]
error occurs while installing the application.
I tried to change min sdk levels, gradle min sdk level but it is not working. Any suggestions?
Make sure the <uses-sdk> line in your manifest matches what's in build.grade, and that your target device/emulator version is in the same range.
Applications that target/compile with the Android L preview currently cannot be run on devices that do not have the L preview.
Change your compile and target versions to API 19 in your build.gradle like so and you should be all set:
android {
compileSdkVersion 19
defaultConfig {
targetSdkVersion 19
}
}

Android Studio 0.2 App that use Google Maps - Gradle modify

I'm developing an App in Android studio. And I want use a Google maps API, but I can't use UI to configure project settings. I tried some different instruction to add maps, but it didn't work. I have to modify somehow build.gradle file? Can you tell me how? Does someone have experience with that?
Thanks for every advice.
If you are on 0.2 it means that you already have Google Repository and Android Repository installed(from Android SDK: terminal$ android sdk).
One of them, has the Google Play services.
Here is a full build.gradle for your module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
Notice how(easily) the play services can be included.
Also gradle version is 0.5.+ so it can be auto updated!
Also another VERY important thing, that wasted me a lot of time is the minimum sdk version!
It must be 8 or above, since google play services aren't supported for lower versions!

Categories