error: cannot find symbol in Android gradle library module unit test - android

I have a test project in IntelliJ (using the Android Studio plugin) and I'm trying to set up unit tests as described here.
When running a junit test the project can't seem to find my sources under src > main > java. The following test
package io.adaptiv.plzwrk.lib;
import junit.framework.TestCase;
import org.junit.Test;
public class AdaptivTest extends TestCase {
#Test
public void testDoStuff() throws Exception {
assertEquals(42, Adaptiv.doStuff());
}
}
gives the error
error: cannot find symbol
assertEquals(42, Adaptiv.doStuff());
^
symbol: variable Adaptiv
location: class AdaptivTest
My 'test' class
package io.adaptiv.plzwrk.lib;
public class Adaptiv {
public static int doStuff() {
return 42;
}
}
The layout of my project looks like this
With settings.gradle
include ':lib'
The project build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
The build.gradle under the lib dir
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
}

Related

Unity Android : unable to resolve class okhttp3.OkHttpClient

I'm trying to deploy an App on Android.
The problem
I first got the following error : can't resolve symbol okhttp and now I keep getting unable to resolve class okhttp3.OkHttpClient because of the importing line.
What I've tried
According to this similar post I added a custom Main Gradle Template
and I added the two following lines :
implementation 'com.squareup.okhttp3:okhttp:3.0.1'
import okhttp3.OkHttpClient;
Here is the complete Gradle file :
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:3.6.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.library'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.okhttp3:okhttp:3.0.1'
**DEPS**}
import okhttp3.OkHttpClient;
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
}
lintOptions {
abortOnError false
}
aaptOptions {
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
}**PACKAGING_OPTIONS**
}**REPOSITORIES****SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

cant import dependency implementation on android studio

I am beginner to android studio and I am trying to import a remote dependency for a library of DatePickerDialog (link for its github) but the import doesn't work for me.
I tried to import it by the Group Id (com.github.wdullaer) and Artifact Name (MaterialDateTimePicker) as it shows in the ProjectStructure/dependencies
I tried - import com.github.wdullaer.MaterialDateTimePicker
I also tried - import com.wdullaer.MaterialDateTimePicker
and more but the import does not work
but
here is my gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and here is the DateTimePicker implementation:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.speedq"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'com.github.wdullaer:MaterialDateTimePicker:v4.2.3' // this is the implementation I cant import
}
if any one knows how can I import it it will be very helpful
that is wrong:
implementation 'com.github.wdullaer:MaterialDateTimePicker:v4.2.3'
first of all dont use v near version, so just remove it
also you got wrong path, read again guide - you should use this:
implementation 'com.wdullaer:materialdatetimepicker:4.2.3'

Cannot find local aar built through Flutter Module

I am trying to add the flutter module as aar dependency on my Android Project. Here is the guide
https://flutter.dev/docs/development/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency
I am able to generate the local AAR and I can see these steps to be done:
1. Open <host>/app/build.gradle
2. Ensure you have the repositories configured, otherwise add them:
repositories {
maven {
url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
3. Make the host app depend on the Flutter module:
dependencies {
debugImplementation 'com.example.animation_module:flutter_debug:1.0
profileImplementation 'com.example.animation_module:flutter_profile:1.0
releaseImplementation 'com.example.animation_module:flutter_release:1.0
}
4. Add the `profile` build type:
android {
buildTypes {
profile {
initWith debug
}
}
}
In my Android project, I have app module and library module. I want to include this aar in my library module, here is my library module build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
profile {
initWith debug
}
}
}
dependencies {
debugImplementation 'com.example.animation_module:flutter_debug:1.0'
profileImplementation 'com.example.animation_module:flutter_profile:1.0'
releaseImplementation 'com.example.animation_module:flutter_release:1.0'
}
repositories {
maven {
url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
I have also added mavenLocal() at my project's build.gradle in repository. (Tried with and without it) But dependencies are not resolved.
I get an error:
Could not find com.example.animation_module:flutter_debug:1.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
- https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
- https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
- https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
Required by:
project :app > project :animation_flutter_sdk
I know dependency is not present on the remote at https://dl.google.com but it is present in my local and gradle should pick it up from my local. Please help me how to build this project.
I have a project with several library modules and an app module. I faced the same issue as I wanted to start the flutter module from one of my library modules.
I solved it by adding
repositories {
maven {
url '../path/to_your/flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
in both app module and library module build.gradle
I didn't need mavenLocal().
I also needed to add
profile {
initWith debug
}
in each modules build.gradle.
This is now how my app module and library module build.gradle looks like:
App module build.gradle:
plugins {
id 'com.android.application'
}
repositories {
maven {
url '../core/webshop/flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
android {
compileSdkVersion toolVersions.compileSdk
defaultConfig {
...
}
signingConfigs {
release {
...
}
}
buildTypes {
release {
...
}
profile {
initWith debug
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Project modules
implementation project('your_lib_module1')
implementation project('your_lib_module2')
...
}
Library module build.gradle, where you want to add flutter module:
apply plugin: 'com.android.library'
repositories {
maven {
url './flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
android {
compileSdkVersion toolVersions.compileSdk
defaultConfig {
...
}
buildTypes {
release {
...
}
profile {
initWith debug
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Project modules
implementation project('your_lib_module3')
// flutter
debugImplementation 'com.example.animation_module:flutter_debug:1.0'
profileImplementation 'com.example.animation_module:flutter_profile:1.0'
releaseImplementation 'com.example.animation_module:flutter_release:1.0'
...
}
I have the same issue and solve it adding in repositories of settings.gradle inside of dependencyResolutionManagement
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
maven {
url '/yourpath/your_flutter_module/build/host/outputs/repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
}
I have the same problem, it is solved by setting the configurations
android {
buildTypes {
release {
....
}
profile {
....
}
debug {
....
}
}
}
configurations {
// Initializes a placeholder for the profileImplementation dependency configuration
profileImplementation {}
}
dependencies {
debugImplementation xxx
// Then it can work
profileImplementation xxx
releaseImplementation xxx
}
Picking a specific build type in a dependency

Not able to execute testng.xml file from gradle command line

I have created a gradle project with kotlin in android studio for mobile automation And created task in build.gradle While I am executing test from command prompt eg: 'gradle Test' my test is not getting executed(Message is getting printed which is mention on this tasks). When I am executing directly from testng.xml file than scripts is getting executed successfully.
Below sample code for build.gradle
App -> build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.appium.automation"
minSdkVersion 21
targetSdkVersion 28`enter code here`
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'io.appium:java-client:7.0.0'
implementation 'org.assertj:assertj-core:3.12.2'
implementation 'org.testng:testng:6.14.3'
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1'
implementation 'io.cucumber:cucumber-java8:4.3.1'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'io.cucumber:cucumber-testng:4.3.1'
implementation 'io.cucumber:gherkin:5.1.0'
implementation 'com.aventstack:extentreports:4.0.9'
}
tasks.withType(Test) {
print("Hi")
useTestNG(){
println("Hi2")
suites '/app/testng.xml'
println("Hi3")
}
}
Project -> build.gradle
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.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
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I suppose the problem is with test options, try inserting this code to build.gradle in app level.
android {
testOptions {
unitTests.includeAndroidResources = true
unitTests.all {
useJUnitPlatform()
reports {
junitXml.enabled = true
html.enabled = false
}
testLogging {
events "passed", "skipped", "failed"
// to run JUnit 3/4 tests:
testImplementation("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.7.0")
}
}
}
}
This issue was mentioned at: https://github.com/kotest/kotest/issues/622
To execute a concrete test from command line, you can try:
./gradlew test --tests "com.MyTestCkass.myTest"

BR cannot be resolved

I am not able to add notifyPropertyChanged(int itemId) because of certain issue in gradle, i guess!
any help would be well appreciated
public class RegisterForm extends BaseObservable {
#Bindable
public String firstName;
#Bindable
public int getFirstNameLabelVisibility(){
return TextUtils.isEmpty(firstName) ? View.INVISIBLE : View.VISIBLE;
}
public void setFirstNameFromView(String firstNameFromView) {
firstName = firstNameFromView;
// notifyPropertyChanged(BR.firstName); this line is giving error!
}
}
Build.gradle // for App
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.jivrajsingh.databindingimp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
configurations {
apt
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
apt 'com.android.databinding:compiler:1.0-rc0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
}
Build.gradle // for project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.databinding:dataBinder:1.0-rc2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Thanks for your precious time :)
You have the old plugin setup with the new gradle version.
Remove the data binding plugin & its dependency from classpath.
Now it is integrated and all you need is
android {
dataBinding { enabled = true }
}
http://developer.android.com/tools/data-binding/guide.html

Categories

Resources