Currently going through Android Developers "Build Your First Android App in Kotlin" tutorial. Attempting to enable safe args. Running into the following error:
enter image description here
How should I fix this?
So far I have added the id androidx.navigation.safeargs.kotlin to the app level build.gradle file and in the project level build.gradle file I've added the following code to the dependencies block:
def nav_version = "2.5.3"
classpath ("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
Related
I have been trying to compile an app in Android Studio and it was working fine until I tried to add mobile ads.
Information about AS:
Android Studio Electric Eeel | 2022.1.1 Patch 1
Build #AI-221.6008.13.2211.9514443, built on January 21, 2023
I am following this article from Google Devs: https://developers.google.com/admob/android/quick-start#kotlin
I have read many questions and answers here on stackoverflow and also forums and blogs. The majority are from 2016-2021 and I understand a lot has changed since then...
According to the article, I have to include Google's Maven repository and Maven central repository in both my buildscript and allprojects sections on project-level build.gradle file.
My project-level build gradle contains a plugins { } section and when I paste the code form the article I get an error message saying that buldscript { } should be before plugins { }.
So I change that only to receive an error message saying "Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'".
Following the article, I enter my module build.gradle file to add dependencies and I also update the AndroidManifest.xml with the information provided (I also have my actual AdMob ID).
I am also updating my MainActivity.kt file to include the necessary entries to preload Google Mobile Ads SDK.
But I am not able to compile anything anymore. I tried to move the buildscript{} and allprojects{} parts to the module build.gradle (within the app folder) but then I get following error:
A problem occurred evaluating project ':app'.
Could not find method android() for arguments [build_l8adkk1ea3ur5qn0u7k2w4gx$_run_closure1#20be5c4a] on project ':app' of type org.gradle.api.Project.
I have updated gradle to the latest version through Android Studio.
I have the latest version of Android Studio.
I have also specified the minSDK and targetSDK according to the article.
Not sure what to do or what the problem is. And all the solutions provided in various blogs/forums and here on stackoverflow seem outdated.
Thank you in advance
I am completely new to android studio and android development. I followed the instructions from the project page inside the app center. When I try to apply the first step:
Add the SDK to the project
In your app/build.gradle add the following lines:
dependencies {
def appCenterSdkVersion = '4.1.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}
I get the following error in android studio:
Could not find method implementation() for arguments [com.microsoft.appcenter:appcenter-analytics:4.1.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I found this all depends on gradle and it's version but I couldn'd find a version that makes the error disappear
Current gradle versions
I figured that I did put the the dependendcies into the wrong build.gradle file (project instead of module). After moving the lines to the right file and forcing a gradle sync everything works.
I'm following this tutorial on how to manage Gradle dependencies with Kotlin in my Android app and now I would like to use the versions defined in my Versions object in my app module (the scenario is that I have an open source screen and I want to show the library versions). How can I do this?
I have tried adding the buildSrc directory to settings.gradle:
include ':app', ':buildSrc'
and then in my build.gradle file, adding it to the dependencies block:
dependencies {
implementation project(':buildSrc')
}
However, when I try to compile and run, the following error is thrown:
Don't know how to compute maven coordinate for artifact 'Gradle API' with component identifier of type 'class org.gradle.internal.component.local.model.OpaqueComponentIdentifier'.
and there is no much information in the web about this error.
Try to remove the buildSrc module from your settings & build.gradle. Its automatically build and accessible for all other modules in this project.
I'm basically following the migration guide from within Crashlytics (which is pretty much summarized in this post).
I followed the same instructions verbatim, you can see that from my git diff:
Yet when I sync my Gradle, I get this error:
5:02 PM Gradle sync failed: Could not find method compile() for
arguments [com.google.firebase:firebase-core:11.4.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Update
As mentioned in the comments (and as experienced by us at the end), we shouldn't migrate anyway until further notice:
Update 2
In fabric, if you click on Crashlytics, there is a link on the left nav bar that says Firebase, when you click on it you get this ad
The buildscript block is not a place for your application level dependencies. See this answer for more information on the buildscript block.
You need to place your compile or implementation/api(for gradle 3.4+ and android gradle plugin 3.0+) dependencies into the separate dependencies{} block with the rest of your dependencies, that is usually on the same level as your android plugin configuration.
In your project level grade file, you need to add, maven {
url 'https://maven.fabric.io/public'
} to the repositories.
add the following to your dependencies classpath 'io.fabric.tools:gradle:1.25.1''
In your app level Gradle file put apply plugin: 'io.fabric' below apply plugin: 'com.android.application' and under depencies place this implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
place apply plugin:'com.google.gms.google-services' at the bottom of the app level gradle file.
Change compile '...' to implementation '...'
You are using Google Services plugin 3.0.0. The instructions for adding the Crashlytics SDK indicate that 3.1.2 or higher is required:
Note: Crashlytics requires Google Services plugin version 3.1.2 or
higher. Check the com.google.gms:google-services version number in
your project's build.gradle dependencies.
The error is:
File google-services.json is missing from module root folder. The
Google Quickstart Plugin cannot function without it.
Above asked question has been solved as according to documentation at developer.google.com https://developers.google.com/cloud-messaging/android/client#get-config
2018 Edit : GCM Deprecated, use FCM
The file google-services.json should be pasted in the app/ directory.
After this is when I sync the project with gradle file the unexpected Top level exception error comes. This is occurring because:
Project-Level Gradle File having
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.google.gms:google-services:1.3.0-beta1'
}
and App-Level Gradle File having:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services:7.5.0' // commenting this lineworks for me
}
The top line is creating a conflict between this and classpath 'com.google.gms:google-services:1.3.0-beta1' So I make comment it now it works Fine and no error of
File google-services.json is missing from module root folder. The Google Quickstart Plugin cannot function without it.
The document says:
Copy the file into the app/ folder of your Android Studio project, or
into the app/src/{build_type} folder if you are using multiple build
types.
It should be on Project -> app folder
Please find the screenshot from Firebase website
Instead of putting in root folder as given in docs of firebase, just copy the google-json file in the projectname/app 's root folder and it works fine then .
Its just simple !
WINDOWS
Open Terminal window in Android Studio (Alt+F12 or View->Tool Windows->Terminal).
Then type
"move file_path/google-services.json app/"
without double quotes.
eg
move C:\Users\siva\Downloads\google-services.json app/
LINUX
Open Android Studio Terminal and type this
scp file_path/google-services.json app/
eg:
scp '/home/developer/Desktop/google-services.json' 'app/'
Click right above the app i.e android(drop down list) in android studio.Select the Project from drop down and paste the json file by right click over the app package and then sync it....
This error indicates your package_name in your google-services.json might be wrong. I personally had this issue when I used
buildTypes {
...
debug {
applicationIdSuffix '.debug'
}
}
in my build.gradle. So, when I wanted to debug, the name of the application was ("all of a sudden") app.something.debug instead of app.something. I was able to run the debug when I changed the said package_name...
Download the "google-service.json" file from Firebase
Go to this address in windows explorer "C:\Users\Your-Username\AndroidStudioProjects" You will see a list of your Android Studio projects
Open a desired project, navigate to "app" folder and paste the .json file
Go to Android Studio and click on "Sync with file system", located in dropdown menu (File>Sync with file system)
Now sync with Gradle and everything should be fine
google-services.json file work like API keys means it store your project_id and api key with json format for all google services(Which enable by you at google console) so no need manage all at different places.
Important process when uses google-services.json
at application gradle you should add
apply plugin: 'com.google.gms.google-services'.
at top level gradle you should add below dependency
dependencies {
// Add this line
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
}