Cannot import import android.support.v7.widget.RecyclerView; - java

While learning about RecyclerView, I am facing some problem. GreenAdapter Class failed to import “android.support.v7.widget.RecyclerView”. I am using Android Studio 3.1.4. My compile SDK Version is 28. Here's my build.gradle File:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.sunshine.sunshine.app"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':sunshinemodule')
implementation project(':base')
implementation 'com.android.support:design:28.0.0-rc01'
}
I am also sharing the code where the import is not working:

You should add
implementation 'com.android.support:recyclerview-v7:27.1.1' //28.0.0-rc01
After that, Clean-rebuild and Run.

Add this to your gradle:
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
and then click "Sync now".

Right click on app --> Open Module Settings --> Dependencies then on right side click on plus button. Add library dependency and search recyclerview and then add it.

Related

Could not get unknown property 'VERSION_NAME' for project ':library' of type org.gradle.api.Project

When I import the RippleBackground library for my project as a module, following exception was thrown
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'VERSION_NAME' for project ':library' of type org.gradle.api.Project.
But the versionName is already defined in the build.gradle file.
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.skyfishjy.library"
minSdkVersion 11
targetSdkVersion 29
versionName "1.0.1"
versionCode 2
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
}
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
Anyone can explain where the error is?
The publishing script imported on the last line requires some project properties, including VERSION_NAME, GROUP and others.
If you're not going to publish this library remove the line
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
Otherwise you'll need to put all the relevant properties in your gradle.properties file or provide them in the command line. You can open the URL in your browser and understand the properties from it.
Here, VERSION_NAME and versionName are not related.
Note: Android libraries don't have applicationId, versionCode or versionName. These properties are only used in Android apps. You can remove these lines.

Adding android project dependency fails

I am trying to add a dependency to my Android gradle project, and keep getting the following error when building...
A problem occurred evaluating project ':app'.
> Project with path 'externalproject' could not be found in project ':app'.
I have an external java gradle project that I would like to be built before my android app builds.
I have added this new project to my settings.gradle as follows...
include ':app' , ":externalproject"
project(':externalproject').projectDir = new File(settingsDir, '../externalproject')
rootProject.name = 'mayapp'
My build.gradle in the app folder looks as follows...
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.androidapp1"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:26.0.0'
compile project('externalproject')
}
change below
compile project('externalproject')
to
compile project(':externalproject')
Or better to use implementation
implementation project(':externalproject')

what is a dependency for android.media.tv

I try to move android TV app to Android studio. When I try to compile it, I had some import errors. I couldn't find the dependency that I can add to build.gradle to fix these problem. The list of the imports are:
import android.media.tv.TvContentRatingSystemInfo;
import android.media.tv.TvContract.WatchedPrograms;
import com.android.tv.tuner.data.nano.Track.AtscCaptionTrack;
import com.android.tv.tuner.data.nano.Track.AtscAudioTrack;
import com.android.tv.tuner.data.nano.Channel;
The build.gradle is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.android.tv"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "libtunertvinput_jni"
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/usbtuner-res']
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/exoplayer.jar')
compile project(':common')
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-annotations:+'
}
You can't import these because they have #SystemApi annotation. You can check this for the source code of TvContentRatingSystemInfo. I have also checked WatchedPrograms and it also has #SystemApi annotation. I have not checked the other three.
You need to be system app to access these. As you can see here, you need to push your app in the the \system\ folder. You can find detailed information about AOSP build system here.
Solution :
Changing your android.jar to the .jar in this github should enable you to access system API. The reason is your standard android.jar doesn't have system API. So you need to get framework.jar (by adb pull) from emulator and combine it with core.jar then you can have new android.jar which contains system API (system methods and classes are available in the framework.jar from emulator).
Moreover, you should push your apk to \system\priv-app\ folder to access some system API but I don't know why I can access system API without pushing my apk to \system\priv-app\ when I use .jar from that github account.
I feel like I don't write quite clearly but at least now you have more understandings of what you're facing.
android.media.tv and com.android.tv are part of Android SDK. So you don't need to include any additional libraries in gradle.build file.
Just make sure to:
Update your SDK tools to version 24.0.0 or higher
and
Update your SDK with Android 5.0 (API 21) or higher
Example,
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.tvapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
use this in your dependencies "com.android.support:support-media-compat:26.0.2"
and also use tool version "26.0.1"
compiled SDK version 26.
You can add dependencies in app level gradle.
compile 'com.google.android.libraries.tv:companionlibrary:0.1'

Gradle DSL method not found: 'compile()' error

I promise I have looked at all the answers provided.
1) I wanted to use DialogFragment and developers guide suggested to install Support libraries. I agree I did not go through and pick and choose and I asked it to install all 22 Android support libraries (Android support repository already looked installed).
2) Ensured that the project level build.gradle does not have any compile under dependencies. Only the Module: app level build.gradle has the compile.
3) When I attempted to add the compile "com.android.support:support-v4:18.0.+" to the app module build.gradle, it reds on me because the target sdk is 22. So, I go to change it to 18. No dice.
4) Same annoying error: Gradle DSL method not found: compile():The project may be using a version that does not contain the method: open Gradle wrapper.properties OR The build file may be missing a plugin : Apply Gradle plugin
5) I applied every possible plugin.
Any help would be greatly appreciated.
Project level build.gradle:
// 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.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
App level build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '******'
keyPassword '*******'
storeFile file('********************')
storePassword '********'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.blatest"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
<!-- begin snippet: js hide: false -->
<!-- language: lang-html -->
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'dialogkey'
keyPassword 'changeme'
storeFile file('C:/Users/ybxk021/.android/default.keyset')
storePassword 'blabla123'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.dialogtest"
minSdkVersion 8
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.0'
compile 'com.android.support:support-v4:22.2.0'
}
}

Duplicate BuildConfig integrating Unity Ads in Android Studio

I just finished my application and I'm trying to put ads in with Unity Ads.
I went to "File", "Import Module".
Next I went to "File", "Structure Projects", I clicked on my main module, and went to the dependencies tab on the right and clicked the + and 3.Module dependency, and I selected the module of my main
module depends. Now the code is fine.
But when I test my app, the grade build shows me that :
:unityads:compileReleaseJava
:unityads:proguardRelease
Note: there were 1 duplicate class definitions.(http://proguard.sourceforge.net/manual/
troubleshooting.html#duplicateclass)
:unityads:proguardRelease FAILED
Error:Execution failed for task ':unityads:proguardRelease'.
java.io.IOException: Can't write [/Users/Appli/AndroidStudioProjects/The33/unityads/build/
intermediates/bundles/release/classes.jar] (Can't read [/Users/Appli/AndroidStudioProjects/The33/
unityads/libs/unity-ads.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [unity-ads.jar:com/
unity3d/ads/android/BuildConfig.class]))
The Gradle build script for my core project:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "studio.pomme.m.the33"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':unityads')
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.android.gms:play-services-wearable:6.5.87'
}
The Gradle build script for one of the library projects:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "19.1.0"
defaultConfig {}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
}
dependencies {
compile files('libs/unity-ads.jar')
}
I have no idea of what I should to do.
The reason for the problem is that the Unity Ads JAR contains BuildConfig class, which is also generated during the build process. The solution was to import the module using the AAR instead of the JAR.
Remove the existing Unity Ads module ("File"->"Project Structure").
Download the Unity Ads SDK.
Create a module from "unity-ads.aar" ("File"->"New"->"New Module"->"Import JAR/AAR package").

Categories