我无法弄清楚我错过了什么,其他项目工作正常,但这个项目不承认R: 我也遇到了这个错误:
Error:Execution failed for task
':CpcBarcodeOpticonSample:processDebugResources'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'C:\Users\rhajou\AppData\Local\Android\Sdk\build-tools\22.0.1\aapt.exe''
finished with non-zero exit value 1
这是我的代码:
package fr.coppernic.samples.cpcbarcodeopticonsample;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
CollectionPagerAdapter mDemoCollectionPagerAdapter;
ViewPager mViewPager;
public static ActionBar sActionBar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sActionBar = getActionBar();
setContentView(R.layout.activity_main);
// ViewPager and its adapters use support library
// fragments, so use getSupportFragmentManager.
mDemoCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
if (arg0 < 2) {
sActionBar.setSelectedNavigationItem(arg0);
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
// Specify that tabs should be displayed in the action bar.
sActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
}
@Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
if (arg0.getPosition() < 2) {
mViewPager.setCurrentItem(arg0.getPosition());
}
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
}
};
sActionBar.addTab(sActionBar.newTab().setText("Sample").setTabListener(tabListener));
sActionBar.addTab(sActionBar.newTab().setText("About").setTabListener(tabListener));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
错误出现在最后一行之前:“无法解析符号R” 我错过了什么?
注意:我在MainFragment中有相同的错误
更新:这是我的build.gradle文件:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:22.2.1'
}
android {
compileSdkVersion 18
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
//buildTypes {
// release {
// minifyEnabled true
// proguardFile getDefaultProguardFile('proguard-android.txt')
// }
//}
}
apply from: 'repo.gradle'
apply from: 'dependencies.gradle'
我尝试将项目文件夹复制到桌面(它位于桌面上的另一个文件夹中),它实际上正在工作!