Android Studio and google play services - android

I'm getting really frustrated with this. I've managed to make the google play services available in Android Studio but now I can't instantiate an AdView class. I can import import com.google.android.gms.ads.*; no errors there, it just says Unused import but when I try to create an AdView class I get a cannot find symbol error. It also doesn't find com.google.android.gms.ads.AdView or any other class inside that package for that matter.
I tried cleaning/re-building/restarting the IDE but nothing worked so far.
Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/libGoogleAnalyticsServices.jar')
}
Fixed
See this

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'

Proguard doesn't build project with duplicate classes

I have one flavor for specific device. For this device I have .jar file which have custom android sdk(for this device. It contains some custom class which I have to use). And it works fine until I start use proguard. When I build project with proguard I receive this:
...
Note: there were 1504 duplicate class definitions.
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:proguardAppProguard'.
> java.io.IOException: Please correct the above warnings first.
I found that adding a string:
-ignorewarnings
to proguard-android.txt fixes this problem, but it looks like bad solution. Did somebody face this(or similar) problem?
Edit
build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs'
}
}
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
def computeVersionName() {
return "r_1.0"
}
android {
compileSdkVersion 23
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.app"
multiDexEnabled true
String buildSuf = System.getenv("BUILD_NUMBER");
ext.defaultName = project.archivesBaseName;
if (buildSuf != null) {
def vers = Integer.parseInt(buildSuf)
println "VERCODE = ${vers}"
versionCode vers
} else {
versionCode 1000
}
minSdkVersion 16
targetSdkVersion 21
}
productFlavors {
app {
applicationId "com.app"
versionName computeVersionName()
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
disable 'InvalidPackage'
}
signingConfigs {
...
customerProgurd {
storeFile file('../keys/debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
...
}
buildTypes {
...
customerProguard {
debuggable false
jniDebuggable false
minifyEnabled true
proguardFiles rootProject.file('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.customerProgurd
}
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
...
app files('libs/classes.jar') // it's custom sdk
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
...
}

Gradle Espresso package not recognized

i can not import the espresso package
this is my app gradle file
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'XXXXX'
keyPassword 'XXXXX'
storeFile file('XXXX')
storePassword 'XXXX'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId 'my.package.name'
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile project(':customlib1')
compile project(':customlib2')
compile 'com.android.support:support-annotations:22.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
}
i just clean and rebuild my project and update libraries, but when i try to use in my Test
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import com.estratek.postreet.postreet_lib.activities.About;
import static java.util.regex.Pattern.matches;
#LargeTest
public class EspressoTest extends ActivityInstrumentationTestCase2<About> {
public EspressoTest() {
super(About.class);
}
#Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testListGoesOverTheFold() {
onView(withText("Hello world!")).check(matches(isDisplayed()));
}
}
this line give me error, and i can't import the not found functions:
onView(withText("Hello world!")).check(matches(isDisplayed()));
Am i missing something?
Manually invoking the gradle task sometimes helps as well. Try running ./gradlew assembleAndroidTest from the terminal.
Check if you added correct maven repositories in repositories section. Such mavenCentral() mavenLocal()

error: duplicate class: android.support.v7.appcompat.R

When I try to compile my project I get this error message "Error:(9, 14) error: duplicate class: android.support.v7.appcompat.R". I'm using android studio and I have the latest SDK packages.
gradle for the module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile files('libs/commons-codec-1.10.jar')
compile "com.android.support:appcompat-v7:22.0.0"
}
Gradle file for the Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
these are my gradle files for the project
Move "compileOptions" outside of your "defaultConfig".
I also updated your "buildToolsVersion".
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions { // <-- Moved this outside of your defaultConfig
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile files('libs/commons-codec-1.10.jar')
compile 'com.android.support:appcompat-v7:22.0.0' // <-- brings in support-v4
}

Categories

Resources