Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Using a debug "applicationIdSuffix" causes compilation errors #1888

Closed
tpesce opened this issue Nov 4, 2016 · 6 comments
Closed

Using a debug "applicationIdSuffix" causes compilation errors #1888

tpesce opened this issue Nov 4, 2016 · 6 comments

Comments

@tpesce
Copy link

tpesce commented Nov 4, 2016

Adding this to my project:

debug {
   applicationIdSuffix ".debug"
}

causes builds to fail:

$ ./gradlew clean assemble
[...]
:app:compileDebugJavaWithJavac
error: The generated com.fubar.appidsuffixtest.debug.R class cannot be found
1 error
:app:compileDebugJavaWithJavac FAILED

I've been able to reproduce this with a simple project:

Android Studio 2.2.2
AA 4.1.0
android-apt 1.8

Starting with a new project, built from the "Empty Activity" project (min SDK 22, compile/target SDK 25), I then configure the Gradle build files as per instructions and add the debug app ID suffix. After this step the project continues to build successfully.

I then add modify activity_main.xml to add an id to the TextView:

<TextView
    android:id="@+id/hello"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

and update MainActivity.java with corresponding annotations:

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {

    @ViewById(R.id.hello)
    TextView hello;
}

At this point building the project produces the error about the missing R class. The log file shows the same info as the error:

12:07:42.167 [Daemon worker] ERROR o.a.i.r.ProjectRClassFinder:47 - The generated com.fubar.appidsuffixtest.debug.R class cannot be found

If I remove the debug app ID suffix, the project builds successfully once again. It seems that the application id is being used to resolve the R class:

debug {
   applicationIdSuffix ".wrong"
}

Results in:

error: The generated com.fubar.appidsuffixtest.wrong.R class cannot be found
@WonderCsabo
Copy link
Member

WonderCsabo commented Nov 4, 2016

You should add the following to your app-level build.gradle:

apt {
  arguments {
    resourcePackageName "com.fubar.appidsuffixtest" // or android.defaultConfig.applicationId
  }
}

@tpesce
Copy link
Author

tpesce commented Nov 4, 2016

Thank you!

I also just found the comment on the Gradle config wiki page that said to do the same thing. Apologies for the obvious RTFM issue.

@tpesce tpesce closed this as completed Nov 4, 2016
@darzul
Copy link

darzul commented Jun 13, 2017

Hello guys

First of all, thanks for your amazing work on AndroidAnnotation :)

I try to build my app with AndroidAnnotation 4.3.1 and last gradle version:

  • com.android.tools.build:gradle:3.0.0-alpha3 in project build.gradle
  • gradle-4.0-rc-3 in gradle-wrapper.properties

everything worked fine until I want to use applicationIdSuffix

debug {
   applicationIdSuffix ".debug"
}

-> Impossible to generate AndroidAnnotation classes, I got errors such as:
Error:(X, X) error: cannot find symbol class MyClass_

I tried with the following javaCompileOptions in defaultConfig but the result is the same:

javaCompileOptions {
  annotationProcessorOptions {
    arguments = ["resourcePackageName": android.defaultConfig.applicationId]
  }
}

Is AndroidAnnotation compatible with this new gradle version?

@dodgex
Copy link
Member

dodgex commented Jun 13, 2017

I just tested this setup with my current work in progress app and it works.

I assume you have som errors while processing. You should check the full error log carefully.

@darzul
Copy link

darzul commented Jul 11, 2017

It works with new gradle tool version :)

thanks!

@juanmendez
Copy link

juanmendez commented Jan 31, 2018

I bumped into it using kapt. I have a project which is using the debug prefix and also works with Android Annotations. So I am looking at the AA demo by @WonderCsabo, and he answers in this thread as well. So the same issue, and solution.

kapt { arguments { arg("resourcePackageName", "com.fubar.appidsuffixtest") //or android.defaultConfig.applicationId } }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants