Unity Android : unable to resolve class okhttp3.OkHttpClient - android

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**

Related

Error:Failed to resolve: com.google.android.gms

Error:Failed to resolve: com.google.android.gms:play-services-basement:[11.0.4]
Error:Failed to resolve: com.google.android.gms:play-services-tasks:[11.0.4]
When i used android studio 2.3.2 version my project build successfully but after updated to android studio version to 2.3.3 and updated google play services i am getting this error please help.
There is no play-services-basement and play-services-tasks folder in my folder
when i comment this "compile 'com.google.android.gms:play-services-location:11.0.4'" line my project compiling fine if i uncomment then my project not compiling
Project Gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
jcenter()
}
}
ext {
compileSdkVersion = 25
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
minSdkVersion = 14
targetSdkVersion = 25
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "package"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.github.beyka:androidtiffbitmapfactory:0.9.6.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
}
project gradle file:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}

can't call kotlin module from java module

I want to have an android app in java, but one library module in kotlin. However when I try to run the app in my phone, there's an error saying that it can't find my Kotlin class. This is my kotlin class:
package com.example.mylibrary
import android.util.Log
class A {
fun helloWorld(){
Log.d("Kotlin", "Hello World!")
}
}
and gradle file for my kotlin module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
ext.kotlin_version = '0.6.+'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
Here's my main activity:
package com.example.uisample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.mylibrary.A;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
A obj = new A();
obj.helloWorld();
}
}
Notice how android studio imports com.example.mylibrary.A instead of com.example.mylibrar.Akt as the reference says. Android studio reports no errors before compiling.
Gradle file for app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.uisample"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':mylibrary')
}
After running the project, gradle throws this error: "cannot find symbol class A". What am I doing wrong?
A few things:
Apply the kotlin-android plugin to your library module build.gradle (see the docs):
apply plugin: 'kotlin-android'
As it stands now, you're not even telling gradle to compile Kotlin files.
Your buildscript block should probably be at the top-level build.gradle rather than the module build.gradle.
Consider updating the fully released version of Kotlin 1.0.1-2
For that, you need to add
buildscript {
ext.kotlin_version = '1.4.30' <-- This line
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" <-- This line
}
}
In the gradle.build (project)
and then add the
apply plugin: 'kotlin-android'
In the gradle.build (App)

External library: Cannot resolve symbol

I am using BetterSpinner in my app.
I have simply included it like that:
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
When I try to use it Android Studio even does not suggest to import the library and marks BetterSpinner red:
The code:
BetterSpinner textView = (BetterSpinner)
findViewById(R.id.registration_spinner_stufe);
textView.setAdapter(adapter);
Where is the mistake that Android Studio does not import the BetterSpinner library into my Fragment class?
The solution
"File" -> "Invalidate Caches..." -> "Invalidate and Restart"
did not work for me..
import com.weiwangcn.betterspinner.library.BetterSpinner;
import com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner;
Was ignored by Android Studio:
My complete grade file:
[app]
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.example.jublikon"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main { res.srcDirs = ['src/main/res', 'src/main/res/drawable/ic_action_search.png'] }
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Google Libraries
compile 'com.android.support:appcompat-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.github.navasmdc:MaterialDesign:1.5#aar'
compile 'com.github.rey5137:material:1.2.1.6-SNAPSHOT'
compile 'com.github.paolorotolo:appintro:3.3.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
}
[project]
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
mavenCentral()
}
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}

Error:(19, 0) Gradle DSL method not found: 'android()' not solved

I have the problem:
Error:(19, 0) Gradle DSL method not found: 'android()'
-The project 'x' may be using a version of gradle thet does not contais the method
Open gradle wrapper file
-The build file may be missing a gradle plugin
Apply gradle plugin
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
android {
buildToolsVersion '23.0.0'
}
dependencies {
}
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
compileOptions {
encoding "UTF-8"
}
defaultConfig {
applicationId "es.albertoramos.pfcalbertoramos"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
How fix this problem?
Delete:
android {
buildToolsVersion '23.0.0'
}
dependencies {
}
from your top-level build.gradle.

Robospock and gradle build variants?

I'm using Robospock to perform unit testing and mocking with gradle. This worked great until I added gradle build variants to the mix.
My android build.gradle file:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "0.0.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
uat {
packageName "com.acme.dev"
}
stage {
packageName "com.acme.staging"
}
prod {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.mcxiaoke.volley:library:1.0.4'
}
My robospock build.gradle file:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'org.robospock:robospock-plugin:0.4.0'
}
}
repositories {
mavenCentral()
}
apply plugin: 'groovy'
dependencies {
compile "org.codehaus.groovy:groovy-all:1.8.6"
compile 'org.robospock:robospock:0.4.4'
compile 'cglib:cglib-nodep:2.2'
compile 'org.objenesis:objenesis:1.3'
}
project.ext {
robospock = ":Mothership" // project to test
}
apply plugin: 'robospock'
The Android gradle plug-in offers me build variant tasks such as assembleProd, assembleProdDebug, assembleStageDebugTest. Can I pass something to Robospocl in my build.gradle so that it can participate in the build variants?
Currently when I execute ./gradlew robospok, it cannot find the classes defined in com.acme.dev or com.acme.staging

Categories

Resources