Reputation: 12478
I notice that with Java8 there is no problem with viewBinding in AndroidStudio (Arctic Fox).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
However, once I set compileOptions
to JavaVersion.VERSION_11
, AndroidStudio always falsely shows viewBiding(s) errors though it can compile and run with no problem.
I tested this with a fresh new project in AndroidStudio ArcticFox. It suggests to import the class. After imported, it says Package not found:
Is this AndroidStudio's bug, or are there any misconfiguration about Java compiler setting in my AndroidStudio?
All I did something particular was JavaVersion.VERSION_11
.
Upvotes: 8
Views: 2801
Reputation: 176
As google's support answered: This issue has been fixed and landed in BB canary 8. It is specific to Java 11.
Upvotes: 16
Reputation: 3261
I had this issue, and I did the following:
gradlew help --scan
, it will generate a report that tells will what you should edit before migrate to Gradle 7.0
gradle.properties
and distributionUrl
to https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
Project build.gradle
and set the classpath to com.android.tools.build:gradle:7.0.0
.Upvotes: 0
Reputation: 11
remove the import line from your project and import it again by pressing Alt+Enter then inform me
import com.myapplication.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
}
}
Upvotes: 0