I wanted to add JaCoCo to an existing Android Studio Project. In my settings.gradle I edited:
pluginManagement {
gradle.ext.kotlin_version = "1.6.0"
repositories {
google()
mavenCentral()
}
def versionsProp = new Properties()
versionsProp["myapp.version.level"] = "7.1.0-beta05"
def versionsPropFile = file("local.properties")
if (versionsPropFile.canRead()) {
versionsProp.load(new FileInputStream(versionsPropFile))
}
def levelVersion = versionsProp["myapp.version.level"]
plugins {
id("com.android.application") version "$levelVersion"
id("com.android.library") version "$levelVersion"
id("org.jetbrains.dokka") version "1.4.30"
id("org.jetbrains.kotlin.android") version "$gradle.ext.kotlin_version"
id("org.jacoco.core") version "0.8.7"
} }
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
mavenLocal()
} }
rootProject.name = "TestApp"
include ":app"
include ":mylib_1"
include ":mylib_2"
include ":docs"
Especially I added JaCoCo in plugins section. According to this medium article :
Now inside each module’s build.gradle file apply the newly created
jacoco.gradle as such: apply from: "$project.rootDir/jacoco.gradle"
But in my app modules build gradle (I've shortened away stuff commented there) I have follwing structure:
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}
android {
compileSdkVersion = 31
buildToolsVersion = "31.0.0"
defaultConfig {
applicationId = "org.example.myapp"
// minSdkVersion(21), targetSdkVersion(31) ..
}
// buildTypes, flavorOptions, compose options
// compile options, kotlinOptions, buildFeatures, packagingOptions, lintOptions
}
dependencies {
implementation(fileTree(include: ["*.jar"], dir: "libs"))
implementation("androidx.activity:activity-compose:$compose_activity_version")
implementation("androidx.appcompat:appcompat:$appcompat_version")
testImplementation("junit:junit:4.13.2")
implementation(project(":org_mylib_1"))
implementation(project(":org_mylib_2"))
}
So where or how am I supposed to add the apply from: "$project.rootDir/jacoco.gradle"?
Related
Hello i am trying to import a library called amulyakhare from github into my android studio project but i keep getting the following error after syncing:
Failed to resolve: com.amulyakhare:com.amulyakhare.textdrawable:1.0.1
Show in Project Structure dialog
Affected Modules: app
You can find the github page of the library here :
#github/amulyakhare
This is the code in the build.gradle(app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.androidnewchatapp"
minSdkVersion 28
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'
}
}
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//Firebase UI
implementation 'com.firebaseui:firebase-ui-auth:7.1.1'
implementation 'com.firebaseui:firebase-ui-database:7.1.1'
//viewPager 2
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
//ButterKnife
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor'com.jakewharton:butterknife-compiler:10.2.3'
//Dexter
implementation 'com.karumi:dexter:6.1.2'
//TextDrawable (The amulyakhare Library)
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
//EventBus
implementation 'org.greenrobot:eventbus:3.2.0'
//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor'com.github.bumptech.glide:compiler:4.11.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.firebase:firebase-analytics'
}
i dont know if there is something wrong wih the library or there is something missing in my code. Thank you in adnvance to those who can help out
Add this to your settings.gradle
jcenter()
maven {
url 'https://jitpack.io'
}
if you're using android studio bumblebee settings.gradle should be like this
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
maven {
url 'https://jitpack.io'
}
}
}
rootProject.name = "You App Name"
include ':app'
If not work, try to import jar file, download from this
I figured it out
1)In your project level gradle add jcenter()
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
JCenter Maven repository is no longer receiving updates: newer library versions may be available elsewhere
so You need to find same library somewhere else. or you can fork yourself and upload to jitpack
OR
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.alvinhkh:TextDrawable:f9f516c43b'
}
https://jitpack.io/#alvinhkh/TextDrawable/f9f516c43b
ADD these Simple Lines In Build.Gradle
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
maven { url "https://www.jitpack.io" }
jcenter()
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies {
//Your dependencies here
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://www.jitpack.io" }
maven { url 'https://jitpack.io' }
mavenCentral()
}
}
And in Build.Gradle (App)
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
Will work 100%
I am trying to upgrade my Google Play Services library so I can use the newest Android Gradle (3.2) and Android SDK version (28). The issue is all of my GMS imports cannot be resolved.
Examples:
import com.google.android.gms.common.api.GoogleApiClient;
and
import com.google.android.gms.games.Games;
I've already looked at various questions that have issues with importing these libraries but none are up-to-date or appear to fix my issue. I've tried invalidating cache/restart, clean/rebuild project. Currently I am importing a google-play-services_lib library, which has the bundled GMS as a dependency: com.google.android.gms:play-services:12.0.1
My project build.gradle:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
apply plugin: 'com.android.application'
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.exampleapp"
minSdkVersion 14
targetSdkVersion 28
versionCode 34 // increment with every release
versionName '3.0.5' // change with every release
setProperty("archivesBaseName", "example_$versionName")
}
signingConfigs {
release {
keyAlias = "example key alias"
}
}
buildTypes {
release {
minifyEnabled true
}
}
}
dependencies {
implementation project(':google-play-services_lib')
implementation project(':appcompat_v7')
}
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
My module/app build.gradle:
buildscript {
repositories {
google()
jCenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v4:22.0.0'
compile 'com.google.android.gms:play-services:12.0.1'
}
android {
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Hopefully there is a way to resolve these import errors, which seems to be a disconnect between the gradle building of support libraries and the actual project itself...
Found it. For a migration from way-way back (like target API <= 21), get rid of using the bundle/manual library and stick with a newer Gradle version:
Remove the meta tag from Android Manifest that specifies a Google Play Services version (the bundled version)
Remove your google-play-services_lib
Add the necessary GMS dependencies to the project-level build.gradle, whether manually or in File → Project Structure → MyApp Module → Dependencies tab and add library, even if it doesn't show in the new Android Studio's library search.
Example: implementation 'com.google.android.gms:play-services-base:16.0.1'
I know this was fairly obvious but this might be a good post for migrating somewhat-old Android apps that use GMS to newer versions. This at least lets you pick which GMS modules to use rather than the bulky bundle.
I have some problems while running flutter in android studio
This is my error
Launching lib\main.dart on Moto C Plus in debug mode...
Initializing gradle...
Resolving dependencies...
Finished with error: Please review your Gradle project setup in the android/ folder.
* Error running Gradle:
Exit code 1 from: D:\FlutterPrograms\app\android\gradlew.bat app:properties:
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to E:\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
Where:
Build file 'D:\FlutterPrograms\app\android\app\build.gradle' line: 25
What went wrong:
A problem occurred evaluating project ':app'.
Could not resolve all artifacts for configuration 'classpath'.
Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
This is my buid.gradle file
buildscript {
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my gradle error
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.shanmukh.app"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
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'
}
There were lots of similar issues raised the past days, that could be solved by adding the google() repository in first position in the repositories block of the build scripts.
See detailed explanation in the following answers:
couldn't locate lint-gradle-api-26.1.2.jar for flutter project
Could not find play-services-basement.aar
https://stackoverflow.com/a/52982816/6899896
Could not find com.android.tools.build:aapt2:3.2.0
The root cause , related to missing libraries in Jcenter, is explained in detail here : https://stackoverflow.com/a/50885939/6899896
Open the root flutter folder in your computer, and open the gradle folder in that root folder (For example C:\flutter\package\flutter_tool\gradle) and add 'google()' to the buildscript. It fixed the issue for me.
Flutter root folder:
Add 'google()' to the buildscript:
I found a solution!
Go to your flutter folder. After you need to find flutter.gradle. On my PC:
C:\src\flutter\packages\flutter_tools\gradle
Open flutter.gradle with note or notepad and change
buildscript from this:
repositories {
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
}
to this:
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
}
I am getting this error in the gradle file:
Error: Failed to resolve: com.google.android.gms:play-services-measurement:10.2.4
-Install Repository and sync project
-Open File
-Show in Project Structure dialog
But I don't use the play-services-measurement in my app.
In the other hand, if I click on the link "Install Repository and sync project" nothing happens.
Any could help me with this? I have been wasting days with this issue.
This is my full gradle file:
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileOptions {
encoding "UTF-8"
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
defaultConfig {
applicationId "xxx.yyy.zzz"
minSdkVersion 9
targetSdkVersion 25
versionCode 120
versionName "1.20"
multiDexEnabled true
//Enabling multi dex support due to exceeding the 65K methods dex limit imposed by Android: http://stackoverflow.com/questions/29756188/java-finished-with-non-zero-exit-value-2-android-gradle
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "MyAppName")
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':simple-crop-image-lib')
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:10.2.4'
compile 'com.google.android.gms:play-services:10.2.4' //8.3.0' 10.2.4' 9.0.0' 9.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
//For soap:
compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
}
apply plugin: 'com.google.gms.google-services'
Update Google Repository in Android SDK. Works for me with version 47.
From the firebase doc:
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.4'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
For me worked to remove these lines from the "app build.gradle":
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
And add these to the "project build.gradle":
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
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
}
}
Screenshot http://i.imgur.com/2i41Vih.png
My project is named Pudge. When I open Module settings, I select my project and all the tabs (dependencies, etc.) are missing.
This is probably something stupid, but I don't know what.
Edit: adding more info:
The project has a folder named libraries, and in it there is the folder of the library (facebook in my case)
build.gradle of the main project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'tests/src'
}
}
}
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
}
dependencies {
compile project(':libraries:facebook')
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'com.google.android.gms:play-services:3.2.25'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
build.gradle of the facebook library
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java {
srcDir 'src'
}
res {
srcDir 'res'
}
}
}
}
settings.gradle
include ':Pudge'
include ':libraries:facebook'
As I said in the comments - after I added the library through the gradle files - its working. But the tabs are still missing.
Looking at your main build file, it has the comment in it about being the top-level build file, so it looks like your main module is located at the project root instead of inside a folder. This is probably what's confusing the Project Structure dialog, because when it examines settings.gradle, it expects to see modules in the Pudge and libraries/facebook directories.
If my assumption about your main module being at the project root is correct, if you change your settings.gradle file to this it should work:
include ':'
include ':libraries:facebook'