AndroidAnnotations + Android Studio - The generated null.R class cannot be found - android-studio

I have setup ActiveAndroid as per the wiki instructions using latest version of AndroidStudio. I am using product Flavours. This is my gradle build file:
apply plugin: 'android'
apply plugin: 'android-apt'
apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName android.defaultConfig.packageName
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
a {
packageName "com.a.a"
}
b {
packageName "com.a.b"
}
c {
packageName "com.a.c"
}
}
}
dependencies {
apt "org.androidannotations:androidannotations:3.0+"
compile "org.androidannotations:androidannotations-api:3.0+"
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Gradle build files but when I compile/go to debug on the device I receive two errors:
Error:: The generated null.R class cannot be found
and
Error:Execution failed for task ':ml:compileADebugJava'.
Compilation failed; see the compiler error output for details.
I have tried numerous setups for my build file but cannot for the life of me get it work. Also when I try and change my AndroidManifest from:
android:name="com.a.a.MainActivity"
to
android:name="com.a.a.MainActivity_"
it states that class cannot be found.
I am using latest version of Gradle and latest version of ActiveAndroid.
Any help would be much appreciated.

I know its late, but it might help someone.
This happens when you modify the applicationId. The script provided in example assumes that you have declared "android.defaultConfig.applicationId". In most of the cases its null, and hence it generated null.R. Either you can define the variable or change the code to following:
defaultConfig {
// Rest of Config
javaCompileOptions {
annotationProcessorOptions {
arguments = ["resourcePackageName": "<Original Package Name>"]
}
}
}
Note that original Package name should be same as the location of R in your activity.
Hope it helps!

I have just got into this same problem, solved by adding packageName to the defaultConfig:
Sample:
defaultConfig {
packageName "com.example.myapp"
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
Change com.example.myapp according to the name specified in your AndroidManifest.xml.
Hope this helps.

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.your.app"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
It works for me.

I was facing this problem, so I just removed this line:
resourcePackageName android.defaultConfig.packageName
and it worked.

apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
In my case, It Worked.

change the applicationId==package in the manifest.
100% success.

I had the same problem. I've update the build.gralde file as follow.
For Java I've added:
android {
defaultConfig {
applicationId "<your.application.id>"
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
arguments = ["resourcePackageName": android.defaultConfig.applicationId]
//arguments = ['androidManifestFile': variant.outputs[0].processResources.manifestFile]
}
}
}
}
For Koltin I've added:
kapt {
arguments {
arg("resourcePackageName", android.defaultConfig.applicationId)
//arg("androidManifestFile", variant.outputs[0]?.processResources?.manifestFile)
}
correctErrorTypes = true // add this if you use data binding
}

Related

How change Android Studio project api version to 23

I use Android Studio3.2.
I create a project use api version 28.
Now I need change api version to 23.
So I edit build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
}
And I change "AppCompatActivity" to "Activity"
But building faild:
Android resource linking failed
Output: error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
.............................
Try to look inside you XML for a view that has style type mentioned in that error.
Also, try to go File/ InvalidateCaches
compileSdkVersion and targetSdkVersion should match and apart from that
you have to include the following support library to support api 23
implementation 'com.android.support:appcompat-v7:23.0.0'
then now sync project and check.
Hope this will help

Android studio 3: Could not find the AndroidManifest.xml file

after migrating to Android studio 3 I'm unable to compile as I' have folowing errors:
Error:Could not find the AndroidManifest.xml file, using generation
folder
[/home/salacr/git/Evotech/app/build/generated/source/apt/debug])
Error:Parceler: Code generation did not complete successfully. For
more details add the compiler argument -AparcelerStacktrace
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
It might be connected with usage of android anotation my app/build.gradle looks like this:
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
def AAVersion = '4.3.1'
def parcelerVersion = '1.1.9'
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
applicationId "com.my.app"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
signingConfigs {
release {
storeFile file("******")
storePassword "******"
keyAlias "******"
keyPassword "******"
}
}
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
/*
// map for the version code
project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
*/
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "org.parceler:parceler-api:$parcelerVersion"
annotationProcessor "org.parceler:parceler:$parcelerVersion"
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:multidex:1.0.2'
}
I'm unable to find the root cause for this, any suggestions?
I tried diferent graddle versions as well as using different buildToolsVersion tools, but without effect.
Any suggestions?
Thanks!
EDIT 1: I have found out that problem is here:
splits {
abi {
enable true // enable ABI split feature to create one APK per ABI
universalApk true //generate an additional APK that targets all the ABIs
}
}
Without this everything works as expected. IT seams that this config isn't compatible with androidanotations in new Android studio
EDIT 2: There is already issue in androidanotation: https://github.com/androidannotations/androidannotations/issues/2034
I had similar issue and solved my problem when I updated android annotation version from 4.4.0 to 4.5.0.
Add the following code in build.gradle file under defaultConfig
javaCompileOptions {
annotationProcessorOptions {
arguments = [
"androidManifestFile":"$projectDir/src/main/AndroidManifest.xml".toString()
]
}
}
I solved this problem changed graddle version:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
I had similar issue and solved my problem when I updated android annotation version from 4.4.0 to 4.6.0.

Test running failed: Permission Denial: starting instrumentation ComponentInfo

Test running failed:
Permission Denial: starting instrumentation ComponentInfo{com.xxx.taskmanager.warehouse.tests/android.test.InstrumentationTestRunner} from pid=766, uid=766 not allowed because package com.xxx.taskmanager.warehouse.tests does not have a signature matching the target com.xxx.taskmanager.warehouse
Empty test suite.
This is my app.gradle file
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
signingConfigs {
release
{
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('../keystore.jks')
storePassword 'xxx'
}
}
compileSdkVersion 16
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.0"
testApplicationId "com.xxx.taskmanager.warehouse.tests"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'LICENSE'
exclude 'NOTICE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"FLO_HANDHELD_V${variant.versionName}.apk"
)
}
}
variantFilter { variant ->
if(variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
productFlavors {
production_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2B"
}
stage_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2B"
}
production_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2C"
}
stage_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2C"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files ('libs/android-support-v7-appcompat.jar')
compile files('libs/android-support-v4.jar')
compile project(':taskmanagerlib')
compile files('libs/DataCollection.jar')
androidTestCompile fileTree(dir: 'libs', include: 'robotium-solo-5.3.0.jar')
}
task copyTask(type: Copy) {
from 'build/outputs/apk'
into 'apks'
exclude '**/*-unaligned.apk'
}
task deleteApk(type: org.gradle.api.tasks.Delete){
// delete 'apks'
}
task appBuild(dependsOn: ['deleteApk','clean', 'assembleRelease', 'copyTask']){
assembleRelease.mustRunAfter deleteApk
clean.mustRunAfter deleteApk
copyTask.mustRunAfter assembleRelease
}
I think this error is happening because I have not declared the signingConfigs for test package. If so , how do I declare it. ?
Please help!!
I have solved the issue. Answering it so that it can be useful for someone else.
Solution is for Android Studio :
For the tests to run , the build variant should be debug. Build Variants window is present in the left side of the android studio, if not activated then activate it by click on Build variants tab present on the left side of the android studio.
You either have to change your build variant to debug, or add a testBuildType to your android tag inside your build.gradle file. Like this:
android {
...
testBuildType "release"
}
Clean Your Project.
Uninstall app if already install.
Now Run your project.
It's Completely Working for me.
Had the same problem even with Android Studio 3.x years later. Previous answers did not work for me.
Only cure was to explicitly add the permissions to the test app on the phone.
It worked for me when changed Startapp code to use apk file instead of installed App.
i.e. from :
From :
return GetApp().InstalledApp(Settings.AUTPackageName).EnableLocalScreenshots().ConnectToApp();
To:
return GetApp().ApkFile(Settings.AUTPath).EnableLocalScreenshots().ConnectToApp();

Loading shared libraries with Gradle 2.2.1

I'm trying to use a shared library, libavcodec-56.so, in my Android app and I can't find the way. I'm using Gradle 2.2.1 and Android Studio 1.0. What I have done so far is the following:
-I built libavcodec-56.so from source code using a NDK toolchain.
-I copied libavcodec-56.so into src/main/jniLibs/armeabi
-I'm able to create a .c file in the project and communicate with the java files using private native void nameOfTheNativeMethod()
-I can load some external libraries like ldLibs "m"
However, if I try to use #include <libavcodec/avcodec.h> I get the error
No such file or directory
#include <libavcodec/avcodec.h>
My gradle file looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName "ffmpeg"
cFlags "-std=c99"
ldLibs "log", "m"
}
}
sourceSets.main {
jni.srcDirs = ["src/main/jni"];
//jniLibs.srcDirs = ['src/main/jniLibs'];
}
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:21.0.3'
}
Any ideas?
Thanks in advance
the current NDK support with the gradle android plugin is incomplete and now deprecated. You can't have native dependencies between native local libraries.
The only solution with gradle right now is to directly use ndk-build with your own Makefiles to generate all your libs, with such build.gradle file:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
jniLibs.srcDir 'src/main/libs' //integrate your libs from libs instead of jniLibs
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}

Plugin with id 'crashlytics' not found issue with Android studio latest plugin

For the following gradle build configuration, I am facing Error:(11, 0) Plugin with id 'crashlytics' not found error.
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
apply plugin: 'hugo'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.wiznsystems.android"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/smartconfiglib.jar')
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.jakewharton.hugo:hugo-runtime:1.1.0'
compile 'com.squareup.retrofit:retrofit:1.+'
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.jakewharton:butterknife:5.+'
compile 'de.greenrobot:eventbus:2.2.1'
compile 'fr.avianey:facebook-android-api:+#aar'
compile 'com.squareup.picasso:picasso:2.+'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.4'
compile project(':apptentiveandroidsdk')
}
Am I doing something wrong? or Is there any workaround for making it build?
I had the same issue. What I ended up doing was putting the order of the commands inline with what Crashlytics provided. I had something similar to yours and it didn't work. Once it changed it to the exact order of there docs it worked. Here is what mine looks like now. Hope this helps.
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.joanzapata.android:android-iconify:1.0.6'
compile 'com.github.hotchemi:android-rate:0.3.1'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.github.satyan:sugar:1.3'
compile 'com.crashlytics.android:crashlytics:1.+'
}
android {
compileSdkVersion 19
buildToolsVersion "20"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Try informing the classpath dependency:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
After battling with this error for hours, I ended up deleting the ".gradle" folder on my home directory, and the issue vanished! So, if you are getting this issue, try deleting the .gradle folder first, then rebuild your project.

Resources